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

Accessing the radgrid values in codebehind while Editing

1 Answer 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Berry
Top achievements
Rank 1
Berry asked on 30 Oct 2012, 05:21 PM
hi All,

I have a dropdown (programgroup) in my edit form for which I want to set the selectedvalue in the code behind and not in aspx. For that I have to know the value that is in the radgrid cell for that column. Please see the code below. I have a different datakey and this program group cannot be the datakey.

This is my aspx definition:
In MasterTable View:
   <telerik:GridBoundColumn UniqueName="ProgramGroup" HeaderText="Program Group" DataField="ProgramGroup" DefaultInsertValue="">  </telerik:GridBoundColumn>

In the EditForm Template:
<asp:DropDownList ID = "ddlProgramGroup" runat = "server"  TabIndex="8" Width="200px" DataTextField = "List_Item" DataValueField = "List_Value" DataSource ="<%# dsProgramGroup(true) %>" >
</asp:DropDownList>

In the CodeBehind:
  Private Sub rgSearchResults_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgSearchResults.ItemDataBound
        If TypeOf e.Item Is GridEditFormItem And e.Item.IsInEditMode Then
            Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
            Dim ddlDropDownList As DropDownList = DirectCast(e.Item.FindControl("ddlProgramGroup"), DropDownList)
            If Not IsNothing(ddlDropDownList) Then
                Dim strPrg As String = "VALUE IN THE RADGRID CELL"
                ddlDropDownList.Items.FindByText(strPrg).Selected = True
            End If
        End If
    End Sub

Is there a way to find out the value of the program group is the radgrid_ItemDataBound event

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 31 Oct 2012, 03:35 AM
Hi,

Please try the code snippet to access the cell value while editing.

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
    Dim ddlDropDownList As DropDownList = DirectCast(e.Item.FindControl("ddlProgramGroup"), DropDownList)
    If (ddlDropDownList IsNot Nothing) Then
        Dim parentItem As GridDataItem = TryCast(e.Item, GridEditFormItem).ParentItem
        Dim strPrg As String = parentItem("ProgramGroup").Text
        ddlDropDownList.Items.FindByText(strPrg).Selected = True
    End If
End Sub

Thanks,
Shinu.
Tags
Grid
Asked by
Berry
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or