I have layout template and there is table in it..
now I Bind data from database to list view.
I have member type table in database.
int that there is member type and member name are two field.
I want to color table as per data i got from database.
Means if I got Silver member type than I want to color table as red and if I got Gold member type than I want to display them as different color...
Loading
Dorababu MekaPosted Sep 6, 2010, 7:18 AM
foreach (ListViewItem Item in listView1.Items)
{
if (Item.Index % 2 == 0)
{
Item.BackColor = System.Drawing.Color.Red;
}
else
{
Item.BackColor = System.Drawing.Color.Gold;
}
}
keshu keshvalaPosted Sep 6, 2010, 5:37 AM
hgere is my source code:
con.Open();
cmd = new SqlCommand("exec_search_details @varSub_category='" + txtmat.Text + "', @varCity_name = '" + ddcity.SelectedItem.Text + "' , @varareaname = '" + txtarea.Text + "'", con);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
ListView1.DataSource = ds;
ListView1.DataBind();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["varType"].ToString().Contains("Gold"))
{
HtmlTable tbl = (HtmlTable)ListView1.FindControl("tbllayout");
tbl.Rows[0].BgColor = "#FFFFFF";
}
}
else if (ds.Tables[0].Rows[i]["varType"].ToString().Contains("Free"))
{
HtmlTable tbl = (HtmlTable)ListView1.FindControl("tbllayout");
tbl.Rows[0].BgColor = "#FFFF33";
}
else if (ds.Tables[0].Rows[i]["varType"].ToString().Contains("Platinum"))
{
HtmlTable tbl = (HtmlTable)ListView1.FindControl("tbllayout");
tbl.Rows[0].BgColor = "#999ccc";
}
}
please give me example of it..
Dorababu MekaPosted Sep 6, 2010, 4:24 AM
Find the index associated with the one you get and color it