I Have Menu Table and product table and MenuId ins the common field Example
Menu Table
MenuId MenuName
11 Shirts
12 Tshirts
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
protected void Page_Load(object sender, EventArgs e)
{
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
Set image url in aspx , something like this
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "your_path" + "ProductImage" %>'
Height="300px" Width="300px"/>
</ItemTemplate>
Plese make sure your_path is physical path where image is stored, for example "~/images/myimg"
and your image name is valid, for example image.jpg
or image1.png
by this method you can show image in gridview.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.