我有一个基础架构网格,可以在更改下拉列表时获取数据 1-我想在每次网格加载数据时隐藏最后一列 2-我还想根据数据更新标题
我正在尝试的问题
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
EntityName.Text = DropDownList1.SelectedItem.Text;
string entity = "t_" + DropDownList1.SelectedItem.Text;
String strConnString = ConfigurationManager.ConnectionStrings["LiveLeaseConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("p_DataList_ByRegardingObject", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@RegardingObjectName", entity);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sqlDataAdapter.Fill(dt);
this.EntityGrid.DataSource = dt;
this.EntityGrid.Columns[6].Hidden = true;
它抛出空引用错误,并且每次加载数据时似乎都没有更新列名。数据正在刷新,但不是列名。这是我的aspx
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Select Entity</asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" ID="EntityName"></asp:Label>
<ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server" Width="100%" Height="50%" StyleSetName="Claymation" >
<Behaviors>
<ig:Sorting>
</ig:Sorting>
</Behaviors>
<ClientEvents Click="NavigateOnClick" />
</ig:WebDataGrid>