下拉列表选择,向内网显示匹配记录 [英] Dropdownlist select , display matching recordsto innergrid
本文介绍了下拉列表选择,向内网显示匹配记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在页面中有一个下拉列表.如果我选择一个下拉列表中的任何一个,则需要将值填充到内部网格控件中.所以现在如何在下拉列表选择索引更改事件时获取内部网格ID.
注意:droplistlist框不在gridview中.那是分开的.
预先感谢,
sundaramoorthy
Hi to all,
I have one dropdownlist in page. if i select any of one dropdown list , i need to populate values to inner grid control. so now how can i get inner grid id while dropdownlist selected index changed event.
Note: droplistlist box not in gridview. That is in separately.
Thanks in advance,
sundaramoorthy
推荐答案
检查此
Hi ,
Check this
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (
SqlConnection con =
new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("usp_test_all", con))
{
cmd.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "OrderAmount";
DropDownList1.DataValueField = "orderID";
DropDownList1.DataBind();
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
using (
SqlConnection con =
new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("usp_test", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", DropDownList1.SelectedValue);
DataTable dt = new DataTable();
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
使用Query中的参数,只需编写代码即可在SelectedIndexChanged事件中将数据加载到GridView中.例如
Simply write code for loading data in to GridView in SelectedIndexChanged event with parameters in Query. Ex.
SqlConnection conString = new SqlConection(ConfigurationManager.ConnectionString["MyCon"].ConnectionString);
string Query = "SELECT * from exTable where Col1 = '"+ddlFlter1.SelectedItem.ToString()+"'";
SqlDataAdaptor adp = new SqlDataAdaptor(Query,ConString);
DataSet ds = new DataSet();
adp.Fill(ds);
GridView1.DataSource= ds;
GridView1.DataBind();
尝试此代码并还原.
Try this code and revert.
这篇关于下拉列表选择,向内网显示匹配记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文