Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i Have Menu Table and product table and MenuId ins the common field
Example
Menu Table
-------------------------------
MenuId MenuName 
-------------------------------
11      Shirts

Product Table 
---------------------------------------------
ProductId ProductName MenuId ProductImage
---------------------------------------------
1         Levisshirts  11     image
2         white shirt  11     image2

have display image in girdview based on drop down selection but the problem is it display same image for every products my code as follows
C#
{
    con.Open();
    if (!IsPostBack)
        ddlbind();
}

private void BindGridData()
{
    SqlCommand command = new SqlCommand("SELECT * from rsa_ProductItemTable where  MenuId=" + Dropsearch.SelectedItem.Value, con);
    SqlDataAdapter daimages = new SqlDataAdapter(command);
    DataSet ds = new DataSet();
    daimages.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
    GridView1.Attributes.Add("bordercolor", "black");
}

public void ddlbind()
{
    SqlCommand command = new SqlCommand("SELECT * from rsa_mastermenu", con);
    SqlDataAdapter daimages = new SqlDataAdapter(command);
    DataTable dt = new DataTable();
    daimages.Fill(dt);
    Dropsearch.DataSource = dt;
    Dropsearch.DataTextField = "MenuName";
    Dropsearch.DataValueField = "MenuId";
    Dropsearch.DataBind();
    Dropsearch.Items.Insert(0, new ListItem("Select", "0"));
}

protected void Dropsearch_SelectedIndexChanged(object sender, EventArgs e)
{
    int imgid = int.Parse(Dropsearch.SelectedItem.Value);
    BindGridData();
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Image img = (Image)e.Row.FindControl("Image1");
        img.ImageUrl = "GridviewImage.ashx?ImID=" + Dropsearch.SelectedItem.Value;
    }
}

What Am i Doing Wrong Please Help me with This Thanks in advance
Posted
Updated 22-Dec-14 23:01pm
v2
Comments
syed shanu 23-Dec-14 20:27pm    
The problem is due to Menu Id as you can see in product table for both image you have the same Menu ID.In this case you need to use ProductId to display different image.

1 solution

according to your code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
this event triggers only once in you r page

call this this line
img.ImageUrl = "GridviewImage.ashx?ImID=" + Dropsearch.SelectedItem.Value;
in
Dropsearch_SelectedIndexChanged(object sender, EventArgs e)
event.
 
Share this answer
 

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