下拉列表未重定向以更新gridview [英] dropdown list not redirecting to update gridview
问题描述
我有一个下拉列表和数据网格..
dropdownlist正在从类别数据库表中选择categoryId值.
我希望从下拉列表中选择该值..
griw视图显示了该类别中的产品.
但是我的问题是,当我在下拉列表中选择catagoryname时,它被选中了.但不会根据类别名称更新gridview..
我认为下拉列表只是选择.不希望更新网格视图.这是代码.我必须做些什么更改才能正常工作.
i have a dropdown list and data grid..
dropdownlist is seleting categoryId value from the categories database table.
i want that as soon as the value is seleted from the dropdown list..
the griw view show the products beleng to that catagory.
but my problem is that when i select catagoryname in the dropdownlist it is seleted . but not updating the gridview on the bases of category name..
i think dropdown list is just selecting. not redircting to update grid view. here is the code. what changes i have to do to work it correctly.
public partial class Admin_procat : System.Web.UI.Page
{
dbcon obj = new dbcon();
protected void Page_Load(object sender, EventArgs e)
{
//dbcon obj = new dbcon();
if (!IsPostBack)
{
string querydr = "select * from ESK_Categories";
SqlDataReader dr = obj.fillcomb(querydr);
DropDownList1.DataSource = dr;
DropDownList1.DataValueField = "CategoryName";
DropDownList1.DataBind();
// Response.Redirect("procat.aspx");
}
if (!IsPostBack)
{
bind();
}
}
public void bind()
{
//string query = "select * from ESK_Products";
string query = "SELECT * FROM ESK_Products LEFT JOIN ESK_Categories ON ESK_Categories.CategoryID=ESK_Products.CategoryID Where ESK_Categories.CategoryName='" + DropDownList1.Text + "'";
DataSet ds = obj.fillgrid(query);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//Response.Redirect("procat.aspx");
}
}
推荐答案
确保dropdownlist AutoPostBack
属性设置为true,并且选中的索引更改事件正在触发.
Make sure dropdownlistAutoPostBack
property set to true and the selected index changed event is firing.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
// calling the bind method.
bind();
//Response.Redirect("procat.aspx");
}
这篇关于下拉列表未重定向以更新gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!