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

Dynamically adding link button in RadGrid Header

2 Answers 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pratap
Top achievements
Rank 1
Pratap asked on 29 Sep 2011, 01:23 PM
Hi Telerik team,


I am trying to add htmlbutton to radgrid header instead of default text header. Below is my code.

void radgrid1_PreRender(object sender, EventArgs e)
        {
            HiddenField hdfSortcolumn1 = (HiddenField)this.Page.FindControl("hdfSortColumn");
            RadGrid RadGrid1 = (RadGrid)Cache["radgrid1"];
            foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
            {
                foreach (GridHeaderItem headeritem in RadGrid1.MasterTableView.GetItems(GridItemType.Header))
                {
                    HtmlInputButton headerButton = new HtmlInputButton();
                    headerButton.Value = col.UniqueName;
                    Session["col"] = col.UniqueName;
                    string strColumn = col.UniqueName.Replace(" ", "%20");
                    string script = " document.getElementById('" + hdfSortcolumn1.ClientID + "').value = '" +
                                            strColumn + "'; RefreshSort('" +  Request.QueryString["ItemID"].ToString() + "');";
                    headerButton.Attributes["onclick"] = script;
                    headeritem[col.UniqueName].Controls.Add(headerButton);
                }
            }
        }
But duplicate header names are coming one is normal text and another one is dynamically added htmlbutton.
How to remove the default header text and only displaying htmlinputbutton.
Hope I can hear from you soon.
Thank you
Pratap.K

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Sep 2011, 01:49 PM
Hello Pratap,

Please take a look into the following forum which discussed similar scenario.
How to Add a Link or button in the radgrid header.

Thanks,
Princy.
0
Pratap
Top achievements
Rank 1
answered on 29 Sep 2011, 02:20 PM
Hi Princy,
Thank you for your quick reply..but i did followed the same code except if statement
if (col.UniqueName == "ProductName") 
Please look in to my code and suggest me the solution.
Thank you.
Tags
Grid
Asked by
Pratap
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Pratap
Top achievements
Rank 1
Share this question
or