[英]Displaying Same images in gridview Based on dropdown selection
I Have Menu Table and product table and MenuId ins the common field Example 我在公用字段中有菜单表和产品表以及MenuId。
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 根据下拉选择在girdview中显示了图像,但是问题是它为每个产品显示了相同的图像,我的代码如下
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 在aspx中设置图片网址,类似这样
<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
请确保your_path是存储图像的物理路径,例如"~/images/myimg"
并且您的图像名称有效,例如image.jpg
或image1.png
by this method you can show image in gridview. 通过这种方法,您可以在gridview中显示图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.