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

How to add GridButtonColumn (Link Button) to grid dynamically ?

3 Answers 869 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Priyal
Top achievements
Rank 1
Priyal asked on 06 Sep 2010, 03:20 AM

Hi,

I have a radGrid which will bind data dynamically using SQDatasource. But I need to change one
GridBoundColumn column to GridButtonColumn in runtime.  (Each and every row has a related .PDF file which need to be opened when user click a cell of that column)

Could you please help me to find how to change GridBoundColumn to GridButtonColumn in runtime?

Regards,
Pri

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Sep 2010, 05:36 AM
Hello Pri,

One suggestion to achieve this functionality is hiding the GridButtonColumn initially and from code behind show GridButtonColumn and hide GridBoundColumn.

ASPX:
<telerik:GridBoundColumn UniqueName="FirstName" HeaderText="FirstName" DataField="FirstName">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn Text="Show" UniqueName="GridButtonColumn" Visible="false">
</telerik:GridButtonColumn>

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
   {    
     (RadGrid1.MasterTableView.GetColumn("FirstName") as GridBoundColumn).Visible = false;
     (RadGrid1.MasterTableView.GetColumn("GridButtonColumn") as GridButtonColumn).Visible = true;
   }
  

Thanks,
Princy.
0
Priyal
Top achievements
Rank 1
answered on 07 Sep 2010, 04:00 AM

Hi Princy,

Thanks for your reply. But my requirement is little different. I have a RadGrid (Auto generated columns) on my web page. I’ve got 8 columns all together (From DB). There is a column called “Document Number”. As I use Auto generate column feature, I get all columns as GridBoundColumns.  I need to change “Document Number” Grid Bound Column to link button or hyper link column. (Each and every row has a related .PDF file which need to be opened when user click a cell of that column)

Eg:

Document Number            Document Title                   dxx                  xxxxx 

10-123-DD-100                      Drawing 1                              …….                     ….

10-123-DD-101                      Drawing 1 of 2

Could you please help me to find how to change GridBoundColumn to GridButtonColumn (Link/Hyperlink) in runtime?

Regards,
Pri

0
Princy
Top achievements
Rank 2
answered on 07 Sep 2010, 05:25 AM
Hello Pri,

If that the case, add one GridHyperlinkColumn with DataNavigateUrlFields and DataTextField as 'DocumentNumber' to the Columns property collection of RadGrid. And from code behind hide the corresponding AutoGenereatedColumn for the field 'DocumentNumber'.
 
ASPX:
<Columns>
    <telerik:GridHyperLinkColumn DataTextFormatString="{0}" DataNavigateUrlFields="DocumentNumber"
        UniqueName="GridHyperLinkColumn" DataNavigateUrlFormatString="#"
        DataTextField="DocumentNumber" HeaderText="Document Number">
    </telerik:GridHyperLinkColumn>
</Columns>

C#:
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
   {
       if (e.Column.UniqueName == "DocumentNumber")
       {
           e.Column.Visible = false;
       }
   }

Thanks,
Princy.
Tags
Grid
Asked by
Priyal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Priyal
Top achievements
Rank 1
Share this question
or