ASP.NET用户控件和网格视图

时间:2018-05-30 06:53:25

标签: asp.net

IN dot net,用户控件在更改时会有一个下拉列表。需要更改网格,但网格不在用户控件内?

我们怎样才能实现它?

1 个答案:

答案 0 :(得分:0)

使用OnSelectedIndexChange将事件绑定到aspx页面上的下拉列表中:

<asp:DropDownList ID="ddlGridType" runat="server" OnSelectedIndexChanged="ddlGridType_SelectedIndexChanged"  AutoPostBack="true" >

然后在您的C#代码后面:

protected void ddlRunType_SelectedIndexChanged(object sender, EventArgs e)
{
    DataTable dtblDataSource = New DataTable();
    string gridType = ddlGridType.SelectedValue;

    //remove the old data from the grid view
    TheGridView.DataSource = null;
    TheGridView.DataBind();

    //get the new data using whatever method you use to get the data
    dtblDataSource = theGridView_GetDataSource(gridType);

    //bind the new data to the list
    TheGridView.DataSource = dtblDataSource;
    TheGridView.DataBind();
}