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

Sending Data Item to Function Called by GridTemplateColumn

2 Answers 357 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 16 Mar 2014, 12:35 AM
Hi -

I often call functions to generate content in my grids and lists.  When I do I always use the DataBinder.Eval() function to get specific fields from the data item and then I send those to my code behind function.  Is there a way to just send the entire data item?

For example below is what I put in my HTML and then the signature of the function in my code behind that takes that data and then generates what I'd like.  If possible I would like to just call CustomerListActions(DataItem As ObjectType).  Thanks!

Ken

HTML CODE
<telerik:GridTemplateColumn><br><%# CustomerListActions(DataBinder.Eval(Container.DataItem, "ID"), DataBinder.Eval(Container.DataItem, "IsDeleted"), DataBinder.Eval(Container.DataItem, "CompanyName"))%><br></telerik:GridTemplateColumn><br>

Function Signature in Code Behind
Public Function CustomerListActions(lngID As Long, intIsDeleted As Integer, strCompanyName As StringAs String<br>End Function

2 Answers, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 19 Mar 2014, 09:59 AM
Hello Ken,

You could pass the data item by simply passing the Container.DataItem in the custom method. Please check out the following code snippet.
Mark-up:
<telerik:GridTemplateColumn>
   
<ItemTemplate>
       
<%# CustomerListActions(Container.DataItem)%>
   
</ItemTemplate>
</
telerik:GridTemplateColumn>
VB:
Public Function CustomerListActions(container As Object) As String
    Dim row As DataRowView = TryCast(container, DataRowView)
    Dim output As String = ""
    output += row("Column1").ToString() & "<br/>"
    output += row("Column2").ToString() & "<br/>"
    output += row("Column3").ToString() & "<br/>"
    output += row("Column4").ToString()
    Return output
End Function

Regards,
Kostadin
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Ken
Top achievements
Rank 1
answered on 25 Mar 2014, 05:26 AM
Thanks!

Container.DataItem was exactly what I was looking for.

Ken
Tags
Grid
Asked by
Ken
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Ken
Top achievements
Rank 1
Share this question
or