Sending Data Item to Function Called by GridTemplateColumn

3 posts, 1 answers
  1. Ken
    Ken avatar
    10 posts
    Member since:
    Nov 2012

    Posted 15 Mar 2014 Link to this post

    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. Answer
    Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 19 Mar 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ken
    Ken avatar
    10 posts
    Member since:
    Nov 2012

    Posted 25 Mar 2014 in reply to Kostadin Link to this post

    Thanks!

    Container.DataItem was exactly what I was looking for.

    Ken
Back to Top