简体   繁体   English

在动态基础设施网格中隐藏列并更新标题

[英]hiding a column in a dynamic infragistics grid and updating header

I have a infragistics grid that gets data when a dropdown is changed 1- i want to hide the last column every time the grid is loaded with data 2- i also want to update header according to data 我有一个Infragistics网格,它在下拉菜单更改时会获取数据1-我想在每次网格加载数据时都隐藏最后一列2-我也想根据数据更新标题

problem I am trying 我正在尝试的问题

     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;

its throwing null reference error and it doesnt seem to update column names each time it loads data.data is getting refreshed but not the column names. 它会抛出空引用错误,并且每次加载数据时似乎都不会更新列名。数据正在刷新,但不是列名。 here is my aspx 这是我的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>   

If your AutogenerateColumns is True - grid column collection will be empty. 如果您AutogenerateColumnsTrue -格列集合是空的。 The trick is to get to the column via Grid Rows. 诀窍是通过“网格行”到达列。

After grid is bound try this: 绑定网格后,请尝试以下操作:

this.EntityGrid.Rows[0].Items[6].Column.Hidden = true;

Just make sure that grid has at least one row. 只要确保网格至少有一行即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM