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

Need to add a linkbutton control to the header of gridboundcolumn[autogenerated column] of radgrid

8 Answers 392 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pradeep Enugala
Top achievements
Rank 1
Pradeep Enugala asked on 04 Sep 2012, 08:01 AM
Hi Telerik team,

In one of my asp page,i'm displaying the radgrid whose datasource is autogenerated columns[autogeneratedcolumns property is set to true for radgrid].Now my new requirement is ,i need to add a control [Link button]to the header of the each autogeneratedcolumn.
I have tried with ItemDataBound,ItemCreated,ColumnCreated events.
finding the header item in these events and then adding the control to the cell..
 if (e.Item is GridHeaderItem)
        {
            TableCell cell = new TableCell();
            LinkButton lnk_edit = new LinkButton();
            lnk_edit.ID = "lnk_" + e.Column.OrderIndex;
            lnk_edit.Text = "Edit";
            lnk_edit.Width = Unit.Pixel(50);
  cell.Controls.Add(lnk_edit);
}

But unable to add the LinkButton control to the header cell of each column.

Please reply ASAP.

Thankyou,
Pradeep

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Sep 2012, 08:11 AM
Hi,

I suppose you want to add a linkbutton to all the boundcolumns. Here is the sample code.
C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridHeaderItem)
 {
  GridHeaderItem item = e.Item as GridHeaderItem;
 foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
 {
  LinkButton link = new LinkButton();
   link.ID = "LinkButton1";
   link.Text = "Edit";
   if (col.ColumnType == "GridBoundColumn")
   {
      item[col.UniqueName].Controls.Add(link);
  }
}
 }
}

Thanks,
Shinu.
0
Pradeep Enugala
Top achievements
Rank 1
answered on 04 Sep 2012, 09:27 AM
Hi Shinu,

Thanks for the reply.Its working fine.
0
Prince
Top achievements
Rank 1
answered on 05 Sep 2012, 06:11 AM
hi Shinu
what if i want to add linkbutton to each and every row in the grid. Also i am adding columns and binding the datasource in code behind.
let me explain you the scenario
i have a DataGrid which is binded with the datasource. now i want to add another column of link type where in when i click on that link it pops up another page.
i want to do all these things in code behind
thanks
0
Shinu
Top achievements
Rank 2
answered on 05 Sep 2012, 06:47 AM
Hi Prince,

You can add a template column dynamically as shown below.
C#:
string templateColumnName = "Name";
  GridTemplateColumn templateColumn = new GridTemplateColumn();
  templateColumn.ItemTemplate = new MyTemplate(templateColumnName);
  templateColumn.HeaderText = templateColumnName;
public partial class TemplateColumn : ITemplate
{
 public void InstantiateIn(Control container)
 {
  LinkButton link = new LinkButton();
  link.Text = "Sample";
  link.ID = "LinkButton1";
  link.PostBackUrl = "Page.aspx";
  container.Controls.Add(link);
 }
}

Also check this help documentation which explains more about creating grid from code behind.

Thanks,
Shinu.
0
Prince
Top achievements
Rank 1
answered on 05 Sep 2012, 07:13 AM
hi Shinu
i am very new telerik grid. i don't know much about this
can you please elaborate it little more
i am pasting my code in which i have added columns to it.
now i want to add one more column which has link button in each cell and when you click on that link it pops up another aspx page.
(very similar to AutoGenerateEditColumn) the only problem with autogeneratededitcolumn is it gives inline editing
instead of that i want to pop up another page

thanks
prince
0
Prince
Top achievements
Rank 1
answered on 05 Sep 2012, 07:49 AM
hey shinu
i am able to bring up link buttons in each row. now how do i add querystring to postback url
for example
when i am clicking link button of first row it should navigate to another page with querystring as first row id and first row name which is there in the radgrid table.

thanks
prince
0
Shinu
Top achievements
Rank 2
answered on 06 Sep 2012, 05:54 AM
Hi,

Try the following code to achieve your scenario.
C#:
public static string value;
public partial class TemplateColumn : ITemplate
{
  public void InstantiateIn(Control container)
  {
     Button btn = new Button();
     btn.Text = "Sample";
     btn.ID = "Button1";
     btn.OnClientClick = "OnClientClick(" + value + ");return false";
     container.Controls.Add(btn);
   }
}
JS:
function OnClientClick(value)
{
  var oWnd = radopen("Window.aspx?CustomerID=" + value, "RadWindow1");
}

Thanks,
Shinu.
0
Edwin
Top achievements
Rank 1
Iron
answered on 06 Jul 2021, 04:45 PM
Necesito ayuda. Como puedo agregar dos botones de + y - en el encabezado de una columna. Les comento que ya tengo dos botones de Mostrar y ocultar que me permiten ocultar y mostrar columnas pero lo que deseo es agregar dichos botones a un costado de los encabezados de una columna. Espero me puedan ayudar pronto, gracias
Doncho
Telerik team
commented on 09 Jul 2021, 06:28 AM

Hi Edwin,

Please note that the official language for Customer Support communication is English, as mentioned on the Support Policy page.

Asking questions in English will help us avoid any misunderstanding hence we can provide more accurate assistance.

As to your question, could you please share some more details about the current case? It would be helpful if you provide the markup declaration of the RadGrid (or let us know if it is generated in the code-behind).

Tags
Grid
Asked by
Pradeep Enugala
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Pradeep Enugala
Top achievements
Rank 1
Prince
Top achievements
Rank 1
Edwin
Top achievements
Rank 1
Iron
Share this question
or