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

RadGrid programatically changes.

6 Answers 369 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CarlosCisneros
Top achievements
Rank 1
CarlosCisneros asked on 15 Jul 2008, 11:40 PM
Hello.

Im using a radgrid, and i need to make several changes, first i need to eliminate "refresh" button from CommandItemSettings coul you help me out?

The second change i need to do is set visible false property to a colum in hierarchy, so far im capable to set the property visible for the master table, but i cannot find how to make it on detail table, i am trying to make it visible or invisible programatically.

thanks for your help.

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Jul 2008, 04:44 AM
Hello Carlos,

Check out the following code to eliminate the RefreshButton.
CS:
if (e.Item is GridCommandItem) 
        { 
            GridCommandItem cmditm = (GridCommandItem)e.Item; 
           //To eliminate the image button
            Button btn1 = (Button)cmditm.FindControl("RefreshButton"); 
            btn1.Visible = false
           //To eliminate the LinkButton
            LinkButton lnkbtn1 = (LinkButton)cmditm.FindControl("RebindGridButton"); 
            lnkbtn1.Visible = false;  
 
       }  

Also, check out the code below for hiding a column in the DetailTable.
ASPX:
<DetailTables> 
        <telerik:GridTableView Name="Detail1"  DataSourceID="SqlDataSource3"
              <Columns> 
                   <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" UniqueName="FirstName" ></telerik:GridBoundColumn> 
                   <telerik:GridBoundColumn   DataField="ToandFro" HeaderText="ToandFro" UniqueName="ToandFro"  ></telerik:GridBoundColumn>                   
              </Columns> 
        </telerik:GridTableView> 
</DetailTables> 

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    {   
       if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == "Detail1")) 
        { 
            foreach(GridColumn column1 in e.Item.OwnerTableView.RenderColumns) 
            { 
                if (column1.UniqueName == "FirstName") 
                { 
                    column1.Visiblefalse
                } 
            } 
        } 
    } 

Thanks
Princy.

0
CarlosCisneros
Top achievements
Rank 1
answered on 16 Jul 2008, 03:50 PM

Hello Princy.

Thanks for your reply, there is no doubt that solves all my problems, but is there a way to do the same inside Page_Load like:

if (permisos[0].mod_cat == "1"){
  RadGrid1.Columns.FindByUniqueName("EditColumn1").Visible = false;
  RadGrid1.Columns.FindByUniqueName("DeleteColumn1").Visible = false;
}

where Editcolumn1 and DeleteColumn1 are UniqueName for columns in MasterTable and the columns i want to hide are inside DetailTable.

Regarding your sugestion abour refresh button i just dont get what are you refering with e.item, i would also like to do it from Page_Load.


Thanks for your help.

0
Accepted
Princy
Top achievements
Rank 2
answered on 17 Jul 2008, 06:36 AM
Hi Carlos,

You can hide columns on PageLoad event as shown below.

CS:
 protected void Page_Load(object sender, EventArgs e) 
    {    
       // To hide a column in the MasterTableView    
        RadGrid1.MasterTableView.GetColumn("FirstName").Visible = false
       // To hide a column in the DetailTable 
        RadGrid1.MasterTableView.DetailTables[0].GetColumn("FirstName").Visible = false;    
     } 

And you could eliminate the RefreshButton in the ItemDataBound event as shown below.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
      if (e.Item is GridCommandItem) 
        { 
            GridCommandItem cmditm = (GridCommandItem)e.Item; 
            Button btn1 = (Button)cmditm.FindControl("RefreshButton"); 
            btn1.Visible = false
            LinkButton lnkbtn1 = (LinkButton)cmditm.FindControl("RebindGridButton"); 
            lnkbtn1.Visible = false;  
       }  
    } 

Thanks
Princy.

0
Carlos
Top achievements
Rank 1
answered on 26 Aug 2008, 04:09 PM
Hi princy.

i'm sorry i was moved from this project to another one with higher priority, i just came back to this one, i checked code you sent me and now it work fine, i just added OnItemDataBound="RadGrid1_ItemDataBound" to my radgrid properties.

thanks.
0
Peter
Top achievements
Rank 1
answered on 13 Dec 2012, 01:33 AM
The above code doesn't work (both columns are hidden).

How do I hide a column and its header per row based on the row's data?
0
Shinu
Top achievements
Rank 2
answered on 13 Dec 2012, 05:01 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
  if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "DetalTable1")
  {
     GridTableView detailTable = (GridTableView)e.Item.OwnerTableView;
     detailTable.GetColumn("Uniquename").Display = false;
  }
}

Thanks,
Shinu.
Tags
Grid
Asked by
CarlosCisneros
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
CarlosCisneros
Top achievements
Rank 1
Carlos
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or