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

Get Header text in ItemDataBound event

4 Answers 429 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MItesh
Top achievements
Rank 1
MItesh asked on 21 Jun 2012, 09:21 PM
I need all column Header text in ItemDataBound, Please help me on this

I have used below code for getting Header in ItemDataBound but not woking

        If e.Item.ItemType = Telerik.Web.UI.GridItemType.Header Then
            If TypeOf e.Item Is GridHeaderItem Then
                Dim Hitem As GridHeaderItem = DirectCast(e.Item, GridHeaderItem)

                For Each column As GridColumn In RadGrid1.Columns
                    Dim s As String = Hitem(column.UniqueName).Text
                Next
            End If
        End If

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Jun 2012, 06:12 AM
Hello Mitesh,

I cannot replicate the issue at my end. Your code is working as expected which returns the header text. If you are setting AutoGenerateColumns as true, try the following code to access the header text for each columns.
VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridHeaderItem Then
        Dim item As GridHeaderItem = TryCast(e.Item, GridHeaderItem)
        For Each col As GridColumn In RadGrid1.MasterTableView.AutoGeneratedColumns
            Dim s As String = item(col.UniqueName).Text
        Next
    End If
End Sub

Thanks,
Shinu.
0
MItesh
Top achievements
Rank 1
answered on 27 Jun 2012, 03:41 PM
Hi Shinu,

Thanks for your help

Now I have another requirement, I need to add DropDownList control in existing column dynamically, I don't need add extra column for that

I don't have any ItemTemplate in my design,  my query is dynamic so I can't add ItemTemplate at design time so I need to add DropDownList control runtime (on ItemDataBound)

can you please help me on this ?
0
Shinu
Top achievements
Rank 2
answered on 28 Jun 2012, 06:24 AM
Hello Mitesh,

One suggestion is you can add a dropdownlist in Prerender event as shown below.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
   foreach(GridDataItem item in RadGrid1.Items)
   {
      foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
      {
        if (col.UniqueName == "UniqueName")
        {
             DropDownList ddl = new DropDownList();
             ddl.ID = "DropDownList1";
             ddl.DataSourceID = "SqlDataSource1";
              ddl.DataTextField = "EmployeeID";
               ddl.DataValueField = "EmployeeID";
               item[col.UniqueName].Controls.Add(ddl);
          }
       }
    }
}

Thanks,
Shinu.
0
MItesh
Top achievements
Rank 1
answered on 28 Jun 2012, 07:57 PM
Thanks Shinu,

your code is working fine now how to handle that DropDownList event in RadGrid while user change anything, I need to create handler for this ?

Once more question also I need to load one control page in Nested grid, i mean under the <DetailTables> or <NestedViewTable> tag ?

Can you please help me on this?

Thanks
Mitesh Darji

Tags
Grid
Asked by
MItesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
MItesh
Top achievements
Rank 1
Share this question
or