在gridview中显示相同的图像基于下拉选择 [英] Displaying Same images in gridview Based on dropdown selection
本文介绍了在gridview中显示相同的图像基于下拉选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有菜单表和产品表以及MenuId在公共字段中
示例
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
根据下拉列表在girdview中显示图像选择,但问题是它为每个产品显示相同的图像我的代码如下
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
{
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;
}
}
我做错了什么请提前帮助我
根据你的代码
推荐答案
protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
此事件触发只有你一次r页
这个叫这个行
img.ImageUrl =GridviewImage.ashx?ImID =+ Dropsearch.SelectedItem .Value;
in
Dropsearch_SelectedIndexChanged(object sender,EventArgs e)
event。
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.
这篇关于在gridview中显示相同的图像基于下拉选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文