选择DropDownList时显示GridView ...... [英] Display GridView while DropDownList Selected.........
本文介绍了选择DropDownList时显示GridView ......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个下拉列表....在选择的下拉列表的基础上,我展示了一个网格视图....plz any1可以帮助我..........
i hv a dropdownlist....On the basis of dropdownlist selected i hv to display a gridview....Plz any1 help me regarding this..........
推荐答案
// Aspx Page
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
// Code Behind
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int Id = int.Parse(DropDownList1.SelectedValue);
fn_BindGrid(Id);
}
public void fn_BindGrid(int Id)
{
Con = new SqlConnection("Connection String");
Con.Open();
Cmd= new SqlCmd("Select * from Table Where Id = @Id",Con)
Cmd.parameters.AddWithValue("@Id",Id)
dt = new SqlDataAdapter(Cmd);
DataSet ds = new DataSet();
dt.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
Con.Close();
}
这篇关于选择DropDownList时显示GridView ......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文