Click here to Skip to main content
15,844,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All..

I want to colour the image in gridview dynamically.. i bind the gridview with a plots details.. if the plot is sold then the particular plotid image should be in red colour.. how to do this.. here is my sample code..

C#
public void Plots_colour(string image)
    {
        cmd = new SqlCommand("Select Plotid from Mas_PlotDetails where Sold_Status='1' and projid='PR001'", con);
        cmd.Connection.Open();
        SqlDataAdapter daa = new SqlDataAdapter(cmd);
        DataSet dss = new DataSet();
        daa.Fill(dss);

        for (int i = 0; i < dss.Tables[0].Rows.Count; i++)
        {
            foreach (GridView row in Gridview.Rows)
            {
               // row.FindControl("Image1"). = System.Drawing.Color.Red;
                
            }
            
        }
    }


I wrote the query in which the sold plots are bindded correctly in dataset, now i want to color the image for the dataset plot id...
Posted
Updated 21-Nov-11 2:35am
v2
Comments
Sunasara Imdadhusen 21-Nov-11 7:35am    
Added <PRE> tag for more readability!
demouser743 21-Nov-11 7:45am    
Check my solution which works perfect for me

1 solution

If you have taken as Image control try as follows

Image ib = ((Image)GridView1.Rows[j].FindControl("img"));
ib.BackColor=System.Drawing.Color.Red;
 
Share this answer
 
Comments
nithibs 21-Nov-11 7:45am    
What my pblm is i want to colour based on filled dataset plot id...
demouser743 21-Nov-11 7:48am    
You can get by changing the code a little bit like

If(plotID=="Your required")
{
apply back color like this
}
nithibs 22-Nov-11 0:25am    
At present i done like this... but it doesn't seems to work.. what's wrong in my code.... i need to finish this today... In dss dataset the plots 1,4,5 which are sold is filled and i bind the grid based on projid there is totally 10 plots... now i want the image to be in red colour for plot id 1,4,5 in grid... how to achieve this...

public void Plots_colour()
{
cmd = new SqlCommand("Select Plotid from Mas_PlotDetails where Sold_Status='1' and projid='PR001'", con);
cmd.Connection.Open();
SqlDataAdapter daa = new SqlDataAdapter(cmd);
DataSet dss = new DataSet();
daa.Fill(dss);

for (int i = 0; i < dss.Tables[0].Rows.Count; i++)
{
foreach (GridViewRow row in Gridview.Rows)
{
Image im = ((Image)Gridview.Rows[i].FindControl("Image1"));
im = new Image();
im.ImageUrl = "~/Images/wchair.jpg";
im.BackColor = System.Drawing.Color.Red;
}

}
}
demouser743 22-Nov-11 2:49am    
Hi color will apply to the back part of the image not on the whole.. Check this image http://img1.imagehousing.com/68/ffe0a978a41090731391b9d8bdec1d4b.jpg

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900