This is a migrated thread and some comments may be shown as answers.

Need to hide column in nested grid

1 Answer 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 2
Brian asked on 29 Aug 2012, 01:16 PM
I have a radgrid, which has a nested template view with another grid in the nested view.  I have a column that contains a hyperlink, which i only want displayed if the user is in a particular role.  I have the role part down, but my problem is I cannot access the grid through the vb.net code behind window.

I try me.gridSchedule, but it is not in the list.

How can I hide this column programmatically?

Thanks...Brian

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 29 Aug 2012, 06:49 PM
Hello,

Please try with below code.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource">
            <MasterTableView DataKeyNames="ID" HierarchyLoadMode="Client">
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                    </telerik:GridBoundColumn>
                </Columns>
                <NestedViewTemplate>
                    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid2_NeedDataSource"
                     OnPreRender="RadGrid2_PreRender">
                        <MasterTableView>
                            <Columns>
                                <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                                </telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                </NestedViewTemplate>
            </MasterTableView>
        </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
      {
          dynamic data = new[] {
            new { ID = 1, Name ="aaa"},
            new { ID = 2, Name = "bbb"},
            new { ID = 3, Name = "ccc"},
            new { ID = 4, Name = "ddd"},
             new { ID = 5, Name ="eee"}
          };
          RadGrid1.DataSource = data;
      }
 
      protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
      {
          if (e.Item is GridDataItem)
          {
              GridDataItem item = e.Item as GridDataItem;
              RadGrid RadGrid2 = item.FindControl("RadGrid2") as RadGrid;
              RadGrid2.Rebind();
          }
      }
 
      protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
      {
          RadGrid RadGrid2 = sender as RadGrid;
          GridDataItem item = (RadGrid2.NamingContainer as GridNestedViewItem).ParentItem as GridDataItem;
          string strID = item.GetDataKeyValue("ID").ToString();
 
          dynamic data = new[] {
            new { ID = 1, Name ="aaa_"+strID},
            new { ID = 2, Name = "bbb_"+strID},
            new { ID = 3, Name = "ccc_"+strID},
            new { ID = 4, Name = "ddd_"+strID},
             new { ID = 5, Name ="eee_"+strID}
          };
 
          RadGrid2.DataSource = data;
      }
      protected void RadGrid2_PreRender(object sender, EventArgs e)
      {
          // Do Your logic here
          RadGrid RadGrid2 = sender as RadGrid;
          RadGrid2.MasterTableView.Columns.FindByUniqueName("ID").Visible = false;
      }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Brian
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or