我有一个infragistics网格,可在下拉列表更改时获取数据 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;
它抛出null引用错误,并且每次加载data.data时都不会更新列名.data正在刷新但不是列名。 这是我的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>
答案 0 :(得分:2)
如果您的AutogenerateColumns
为True
,则网格列集合将为空。诀窍是通过Grid Rows到达列。
绑定网格后尝试:
this.EntityGrid.Rows[0].Items[6].Column.Hidden = true;
确保网格至少有一行。