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

Altering data in listview during binding

3 Answers 76 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 21 Jun 2011, 09:36 PM
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!

Lynn

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Jun 2011, 03:16 PM
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.
Overview.
ListView / First Look.

Thanks,
Princy.
0
Lynn
Top achievements
Rank 2
answered on 23 Jun 2011, 08:52 PM
Princy,

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.
0
Veli
Telerik team
answered on 24 Jun 2011, 07:40 AM
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


Veli
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.

Tags
ListView
Asked by
Lynn
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Lynn
Top achievements
Rank 2
Veli
Telerik team
Share this question
or