Data source and binding to grid column in code behind

2 posts, 0 answers
  1. Clive Hoggar
    Clive Hoggar avatar
    348 posts
    Member since:
    Nov 2008

    Posted 25 Sep 2010 Link to this post

    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
  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 29 Sep 2010 Link to this post

    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
Back to Top