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

Add OnItemDatabound at runtime?

3 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Den
Top achievements
Rank 1
Den asked on 13 Nov 2008, 01:50 AM
I programatically generate radgrid through PlaceHolder.
I also created a sub called "RadGrid1_ItemDataBound".
but how do I execute it since there is no property "OnItemDataBound" in runtime.

I need to be able to click on the link from boundLinkColumn and display radwindow.

Please help.
Thanks
Den

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Nov 2008, 06:25 AM
Hi Dan

The ItemDataBound event will be fired only when the Grid is bound to a DataSource. You can add the event handler for the ItemDataBound event to RadGrid as shown below.

CS:

 RadGrid1.ItemDataBound += new GridItemEventHandler(RadGrid1_ItemDataBound); 

 void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       
    } 



Thanks
Shinu.
0
Den
Top achievements
Rank 1
answered on 13 Nov 2008, 05:40 PM
this is not exactly what I am looking for.

I have already created 


Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs)  
        If e.Item.ItemType = GridItemType.AlternatingItem Or e.Item.ItemType = GridItemType.Item Then  
            Dim item As Telerik.WebControls.GridDataItem  
            item = e.Item  
            item("CustomerID").Text = "Telerik" 
        End If  
End Sub 


But how do I create event handler in aspx since I added the control from the code behind?
is there something like this?
RadGrid1.OnItemDataBound="RadGrid1_ItemDataBound"
Me.PlaceHolder1.Controls.Add(RadGrid1)

to achieve this

 


 radG:RadGrid 
ID="RadGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Skin="Ice" OnItemDataBound="RadGrid1_ItemDataBound" > 




Thanks
Den
0
Shinu
Top achievements
Rank 2
answered on 14 Nov 2008, 07:19 AM
Hi Den,

From what I understood you are creating the RadGrid in the code behind and trying to set the event handler for the ItemDataBound event in the aspx. As far as I know adding an event handler in the code behind for a statically declared Grid is possible but the reverse is not achievable.
Programmatic creation

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