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

RadComboBox in RadGrid - RadComboBox SelectedValue same for all rows

5 Answers 208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jenna Guess
Top achievements
Rank 1
Jenna Guess asked on 11 Jun 2010, 02:23 PM
I have a radgrid that is being dynamically created, adding 1 row at a time.   One of the columns is a radcombobox which is filled using LINQ.  The prerender event is set for the grid to make all rows editable (for multirowedit functionality).  All of that works fine...the problem is that each time I add a new row to the grid the selectedvalue of the radcombobox for previously entered rows changes to match the selectedvalue for the new row.  How do i get each combobox in each row to retain its correct selectedvalue?  To clarify...the selection of each radcombobox is set using: rcb.Text = "SelectedValueText" where "SelectedValueText" is a value which appears in the radcombobox.  I'm thinking the issue has to do with the prerender event calling rebind which executes itemdatabound for each row in the grid but i'm not sure how to make all columns in a row editable on the row level (as each row is added) as opposed to on the gridlevel.  Can you iterate through the cells in a single row to put in edit mode from within the ItemDataBound event?

Code: VB
    Private Sub rgDataEntry_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgDataEntry.ItemDataBound
        If (Session("DataEntry") Is Nothing) Then
            CreateDataTable()
        End If

        If (TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode) Then
            Dim item As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim rcb As RadComboBox = CType(item.FindControl("cboFundingCodeEdit"), RadComboBox)
            Dim db As EcotAppsDataContext = New EcotAppsDataContext

            Dim query = From codes In db.FundingCodes
                        Select codes.FundingCode, codes.FundingCodeID Order By FundingCode Order By FundingCode

            For Each x In query
                Dim rcbItem As New RadComboBoxItem(x.FundingCode.ToString)
                rcb.Items.Add(rcbItem)
            Next

            Dim rcbDefaultItem As New RadComboBoxItem(String.Empty)
            rcb.Items.Insert(0, rcbDefaultItem)

            Dim FundCode As String
            FundCode = Convert.ToString(Session("FundingCode"))
            rcb.Text = FundCode

        End If

    End Sub

    Private Sub rgDataEntry_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgDataEntry.PreRender
        If (Session("DataEntry") Is Nothing) Then
            CreateDataTable()
        End If

        For Each item As GridItem In rgDataEntry.MasterTableView.Items
            If TypeOf item Is GridEditableItem Then
                Dim editableItem As GridEditableItem = CType(item, GridDataItem)
                editableItem.Edit = True
            End If
        Next
        rgDataEntry.Rebind()

    End Sub

5 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 16 Jun 2010, 02:18 PM
Hello Jenna,

Could you please try using following code snippet into the rgDataEntry_ItemDataBound event handler, instead of rcb.Text = FundCode:
rcb.Text = DirectCast(e.Item.DataItem, DataRowView).Row("DatabaseColumnName").ToString()

and let me know if the issue still persists.

Kind regards,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jenna Guess
Top achievements
Rank 1
answered on 16 Jun 2010, 02:39 PM
That worked perfectly!  I had actually fixed the problem but not nearly as simply as your solution.  i had added a call to the following new method from the PreRender event:

    Private Sub RebindRadComboBoxes()
        Dim dt As DataTable = CType(Session("DataEntry"), DataTable)
        Dim x As Integer = 0

        For Each row As GridDataItem In rgDataEntry.Items
            Dim rcb As RadComboBox = CType(row.FindControl("cboFundingCodeEdit"), RadComboBox)
            rcb.Text = dt.Rows(x).Item("FundingCode")
            x = x + 1
        Next

    End Sub

Now i can avoid the extra code.  Thanks!
0
Radoslav
Telerik team
answered on 21 Jun 2010, 10:09 AM
Hello Jenna,

I am glad you solved the problem. In case you experience any further problems, do not hesitate to contact us again!

Greetings,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bill
Top achievements
Rank 1
answered on 09 Oct 2012, 07:32 PM
I have this same issue, could I get solution in C#?
0
Radoslav
Telerik team
answered on 12 Oct 2012, 06:57 AM
Hello Bill,

On the following link you could find a code converter which could be used for converting all provided vb code into this tread to C# code:
http://converter.telerik.com/

Please give it try and let me know if it helps you.

Regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Jenna Guess
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Jenna Guess
Top achievements
Rank 1
Bill
Top achievements
Rank 1
Share this question
or