Altering data in listview during binding

4 posts, 0 answers
  1. Lynn
    Lynn avatar
    186 posts
    Member since:
    Sep 2006

    Posted 21 Jun 2011 Link to this post

    I am trying to use a rad listview contol to display data from a SQL data table.  When the data is loading (binding) I need to examine the data columns and perform some modifications to the data and replace the value in one of the data fields with the modified data.  For example, there are three fields of data in the underlying query.  Field 'A' contains 'abc'.  Field 'B' contains '123'. Field 'C' contains an empty string.  I want to concatenate the contents of Fields 'A' and 'B' and the place the results 'abc123' in Field 'C' which is defined in the listview layout.

    I do these (and other) sorts of modifications to data regularly when using the rad grid.  Can I do them when using your listview control as well?

    When performing these operations in the grid, I use the "ItemDataBound" event and perform a test at the beginning of the event for "If TypeOf e.Item Is GridDataItem Then.....Else....End If" such as:

    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
        If TypeOf e.Item Is GridDataItem Then
                sLat = ""
                sLong = ""
                Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            item("TextActive").Text = "Yes"
        End If
    End Sub

    I have tried doing something similar in the same event for the RadListView control, but always get errors -- you may refer to the attached screen capture.

    Is there a way to modify the data to appear in the radlistview similarly to what I am doing with the radgrid?

    Thanks in advance!

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Jun 2011 Link to this post

    Hello Lynn,

    In RadGrid we are accessing the the columns using the ColumnUnique name. Sice RadListView is having another structure it doesn't have that property.

    Take a look at the following help article and demo for more on this control.
    ListView / First Look.

  3. DevCraft R3 2016 release webinar banner
  4. Lynn
    Lynn avatar
    186 posts
    Member since:
    Sep 2006

    Posted 23 Jun 2011 Link to this post


    I appreciate your time and assistance, however I am unable to find any information that is relevant to the ListView ColumnUnique property in the Knowledge base, the Forums, or in the online doc's.

    I have found some information on the ColumnUnique property in the radgrid, but will not have time until tomorrow or the next day to read this information further and try it with the ListView.

    I had (prior to submitting this forum item) been through all of the examples provided for the ListView and was unable to find any examples of data contents manipulation during run-time from the server side.

    As I said, I will look into the information about the grid's ColumnUnique property and see if I can make that work with the ListView.  After doing so, I will update this forum item at that time.
  5. Veli
    Veli avatar
    2002 posts

    Posted 24 Jun 2011 Link to this post

    Hello Lynn,

    As the RadListviewDataItem does not have a table cell in which you can display some text, you need to take a different approach in RadListView. You can put a Label control in the ItemTemplate (say with ID="Label1") and find this label with RadListViewDataItem.FindControl(). The rest is just setting the label text:

    Protected Sub RadListView1_ItemDataBound(ByVal sender as Object, ByVal e As Telerik.Web.UI.RadListViewItemEventArgs) Handles RadListView1.ItemDataBound
        If TypeOf e.Item Is RadListViewDataItem Then
            Dim label1 as Label = TryCast(e.Item.FindControl("Label1"), Label)
            label1.Text = "Yes"
        End If
    End Sub

    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top