IN dot net,用户控件在更改时会有一个下拉列表。需要更改网格,但网格不在用户控件内?
我们怎样才能实现它?
答案 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();
}