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

Data source and binding to grid column in code behind

1 Answer 116 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 25 Sep 2010, 10:52 PM
HI
I know this can be done but I am struggling with this. Please advise..

I have a grid in which one column is a the file name of a page in a website root.
I am using the default grid edit mode.

I have successfully got a combo box in edit mode to display a list of pages like this:
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
        If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
  
            If e.Item.OwnerTableView.IsItemInserted Then
                'item is about to be inserted  
                Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
                Dim RCBx As RadComboBox = DirectCast(item.FindControl("RadComboBoxPageName"), RadComboBox)
                Dim dirInfo As New DirectoryInfo(Server.MapPath("~/"))
                RCBx.DataSource = dirInfo.GetFiles("*.aspx")
                RCBx.DataBind()
            Else
                'item is about to be edited  
            End If
        End If
  
    End Sub

Now, when inserting I need to get the selected value to bind to the grid column to save the data. How to do this in this scenario?


Also I can display the same list when editing but then I need it to default to the current column value, while still allowing an alternative to be selected from the combo box and then to Update.

Help greatly appreciated!

Thanks

Clive

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 29 Sep 2010, 02:45 PM
Hi Clive Hoggar,

Why don't you use a binding expression to map the column to the RadComboBox SelectedValue property? Here is a demo showing this approach - the third RCB is the one you can use as an example.

Best wishes,
Simon
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
Tags
ComboBox
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or