0
我需要將radgrid指向在下拉列表中選定的表。所以我有調用Rebind()的dropdownList的selectedIndexChanged事件,該事件應該在設置數據源命令的地方觸發radgrid NeedDataSource事件。但它不會開火!以編程方式更改Radgrid中的表 - NeedDataSource不會在Rebind上觸發()
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex > -1)
{
RadGrid1.DataSource=null;
Label1.Text = DropDownList1.SelectedItem.Text; //just for debugging
RadGrid1.Rebind();
}
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
string tableInUse = DropDownList1.SelectedItem.Text;
Label2.Text = "NeedDataSource has been fired"; //just for debugging
RadGrid1.DataSource = SqlDataSource1;
SqlDataSource1.DeleteCommand = "DELETE FROM [" + tableInUse + "] .....";
SqlDataSource1.SelectCommand = "SELECT * FROM [" + tableInUse + "] ORDER BY [Code]";
SqlDataSource1.UpdateCommand = "UPDATE [" + tableInUse + "] SET ....";
}
和標記:
<telerik:RadGrid ID="RadGrid1" runat="server" Culture="it-IT" DataSourceID="SqlDataSource1" OnNeedDataSource="RadGrid1_NeedDataSource">
<MasterTableView DataSourceID="SqlDataSource1">
</MasterTableView>
</telerik:RadGrid>
不知道這是改變關聯到radgrid控件但至少NeedDatasource事件數據庫表的正確方法應該被解僱。我究竟做錯了什麼?
多數民衆贊成在輝煌!感謝您的建議。你絕對正確。這解決了我的問題。 – FeliceM 2014-09-11 14:02:32