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

hide gridbuttoncolumn of detailtable

2 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mydatafactory
Top achievements
Rank 1
Mydatafactory asked on 24 Sep 2008, 02:47 PM
I have a mastertable with several detailtables.

I would like to hide the gridbuttoncolumn (i.c. Delete) of a detailtable dependend of a condition, before the grid will be shown.
I tried to get it work in the 'itemdatabound' and in the DetailTableDataBind, but I got stuck.

the code of the condition is as follows:

If SessionObject.HasRole("DLPRJ") = False Then

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Sep 2008, 04:49 AM
Hi,

Set the Name property for the detail table and try accessing the desired column in ItemDataBound event and hide it accordingly.

ASPX:
<DetailTables> 
     <telerik:GridTableView runat="server" Name="Detail" DataSourceID="SqlDataSource1" AutoGenerateColumns="false"  > 
       <Columns> 
         <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" UniqueName="ProductName"></telerik:GridBoundColumn> 
         <telerik:GridBoundColumn DataField="ProductID" HeaderText="ProductID" SortExpression="ProductID" UniqueName="ProductID" DataType="System.Int32"></telerik:GridBoundColumn> 
        <telerik:GridButtonColumn UniqueName="BtnCol" HeaderText="BtnCol"  Text="Click" ></telerik:GridButtonColumn> 
       </Columns> 
      
     </telerik:GridTableView> 
   </DetailTables> 


CS:
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item.OwnerTableView.Name == "Detail") 
        { 
            foreach (GridColumn col in e.Item.OwnerTableView.RenderColumns) 
            { 
                if (col.UniqueName == "BtnCol") 
                { 
                    col.Visible = false
                } 
            } 
        } 
    } 


Thanks
Shinu.
0
Mydatafactory
Top achievements
Rank 1
answered on 25 Sep 2008, 10:31 AM
Thanx Shinu! It works great.
Tags
Grid
Asked by
Mydatafactory
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mydatafactory
Top achievements
Rank 1
Share this question
or