当我从下拉列表中单击某个项目时,如何显示GridView

时间:2012-12-11 12:38:47

标签: c# asp.net

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList1.AutoPostBack = true;
    Class1 cc = new Class1();
    string k = DropDownList1.SelectedItem.Text;
    DataTable l = cc.table1(k);
    GridView g = new GridView();
    g.DataSource = l;
    g.DataBind();
}

1 个答案:

答案 0 :(得分:0)

您需要设置AutoPostBack=true before DropDownList1_SelectedIndexChanged才能使其生效。如果之前未将AutoPostBack设置为true,DropDownList1_SelectedIndexChanged将永远不会被触发。

您可以在设计时在page_load事件中设置AutoPostBack=true