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

How to add GridButtonColumn (Link Button) to Auto generated grid dynamically

5 Answers 689 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tray
Top achievements
Rank 1
Tray asked on 26 Dec 2012, 07:41 AM
 my requirement is little different. I have a RadGrid (Auto generated columns) on my web page. I’ve got 4 columns all together (From DB). There is a column called “Doc Name”. As I use Auto generate column feature, I get all columns as GridBoundColumns.  I need to change “Doc Name” 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:

Doc Name                           Document Title                     Fields                 

Doc 1                                        Drawing 1                             text                   

Doc 2                                         Drawing 1 of 2                     button

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

Regards,
Tray

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 26 Dec 2012, 08:07 AM
Hello Tray,

You can refer to the following help article for more information about how to achieve your goal: 
http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html

Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Shinu
Top achievements
Rank 2
answered on 26 Dec 2012, 08:39 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if(e.Item is GridDataItem)
 {
   GridDataItem item = (GridDataItem)e.Item;
   HyperLink link = new HyperLink();
   link.NavigateUrl = "Page.aspx";
   link.Text = item["OrderID"].Text;
   item["Doc name"].Controls.Add(link);
 }
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
      GridDataItem item = (GridDataItem)e.Item;
     HyperLink link = new HyperLink();
            link.NavigateUrl = "Page.aspx";
            link.Text = item["OrderID"].Text;
            item["Doc name"].Controls.Add(link);
        }
 }

Thanks,
Shinu.
0
Tray
Top achievements
Rank 1
answered on 26 Dec 2012, 10:00 AM
Hi Shinu,

Thank for your  replay..................in my application am binding data to grid using data set because every time the number of columns of grid not same that's why am using  data set as data source and there is no bound fields in my grid...............


please tell me any any other way to implement this scenario



Thanks,
Tray
0
Shinu
Top achievements
Rank 2
answered on 27 Dec 2012, 06:35 AM
Hi,

You can access the column using its DataField property. You can change the column to hyperlink as shown below.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if(e.Item is GridDataItem)
 {
   GridDataItem item = (GridDataItem)e.Item;
   HyperLink link = new HyperLink();
   link.NavigateUrl = "Page.aspx";
   link.Text = item["Doc name"].Text;
   item["Doc name"].Controls.Add(link);
 }
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
      GridDataItem item = (GridDataItem)e.Item;
     HyperLink link = new HyperLink();
            link.NavigateUrl = "Page.aspx";
            link.Text = item["Doc name"].Text;
            item["Doc name"].Controls.Add(link);
        }
 }
Another approach is to add one GridHyperlinkColumn to the Columns property collection of RadGrid. And from code behind hide the corresponding AutoGenereatedColumn for the field 'Doc name'.

Thanks,
Shinu.
0
Tray
Top achievements
Rank 1
answered on 27 Dec 2012, 06:38 AM
Thanks shinu   it's working perfectly Thank You very much for your support


Thanks ,
Tray
Tags
Grid
Asked by
Tray
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Shinu
Top achievements
Rank 2
Tray
Top achievements
Rank 1
Share this question
or