Hi Experts...
I am here to bind images to gridview dynamically.. What i need is i have to bind image dynamically with a count in database i.e. in plotdetails table if there is a 10 plots in a project then i have to bind the sold plots in red colour image in grid..
i wrote some code but i stuck in bind the images in gridview... here is my code...
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
Sold_Update();
}
public DataSet Sold_Update()
{
cmd = new SqlCommand("Select count(Plotid) from Mas_PlotDetails where Projid='" + DropDownList1.SelectedItem.Text + "'and Sold_Status=1", con);
cmd.CommandType = CommandType.Text;
cmd.Connection.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Mas_PlotDetails");
return ds;
}
What I need is to have to take the plot counts and bind the red colour image in grid if the plot is sold otherwise if the plot is not sold some other colour. I have to bind the no of counts plot to as image in grid.
I done the following code now... its shown the image.. but i should loop the image as per the count.. How to do this...
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView dr = (DataRowView)e.Row.DataItem;
string myflag = dr["Plotid"].ToString();
if (myflag != "0")
{
e.Row.Cells[1].Controls.Clear();
ImageButton img = new ImageButton();
img.ImageUrl = "~/Images/wchair.jpg";
for (int i = 0; i < ;i++ ) // Here how to loop the myflag so that the count is 10, i hav to display the 10 images
{
e.Row.Cells[1].Controls.Add(img);
}
}