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

Building a string from one column's data

3 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
alex bowen
Top achievements
Rank 1
alex bowen asked on 31 Dec 2009, 03:13 PM
Hello,

I have a RAD Grid that has several people's records and the first column is an ID (named SID)field.  What I want to do, is on a button click, build a comma delimited string of all the ID's in the Grid.  I have done this in VB but now need to convert it to C# and m having a bit of trouble with it.  It would be a bit simpler but I actually use the SID column as a link to each person's profile, so it's not as simple as somethinging like:

OwnerTableView.Columns.FindByUniqueName("SID").ToString(); (If I do this I get "<a href=/default.aspx?sid=XXXX>XXXX </a>" as the value, when I only want the XXXX part.

This is what I use in VB to make the string, I use the Data key values (which is the SID field).

Session("sidlist") = Nothing
        Dim SID_ListNewStudents As StringBuilder = New StringBuilder()
        For Each item As Telerik.Web.UI.GridDataItem In SelectedGrid.MasterTableView.Items
            SID_ListNewStudents.Append(item.OwnerTableView.DataKeyValues(item.DataSetIndex).Values(0))
            SID_ListNewStudents.Append(", ")
        Next

Any help would be great, Thanks!

3 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 31 Dec 2009, 04:24 PM
This should be the equivalent:
        Session["sidlist"] = null
        StringBuilder SID_ListNewStudents = new StringBuilder(); 
 
        foreach(GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            ICollection myCollection = item.OwnerTableView.DataKeyValues[item.DataSetIndex].Values; 
            
            foreach(object keyValues in myCollection) 
            { 
                SID_ListNewStudents.Append(keyValues.ToString()); 
                SID_ListNewStudents.Append(", "); 
            } 
        } 

It worked on my end, although I just used a NorthWind connection to extract the ProductID :)
0
alex bowen
Top achievements
Rank 1
answered on 31 Dec 2009, 04:29 PM
Thank you very much, Schlurk!  That will work great.  Another problem I had was not defining my Data key in the MasterTableView of the RadGrid on the front end.  But everything is working now!
0
Schlurk
Top achievements
Rank 2
answered on 31 Dec 2009, 04:43 PM
You are very welcome, glad to hear everything is working! Happy New Year :D
Tags
Grid
Asked by
alex bowen
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
alex bowen
Top achievements
Rank 1
Share this question
or