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

Griddropdowncolumn value on update

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
justin
Top achievements
Rank 1
justin asked on 08 Jun 2012, 02:07 PM
I have a radgrid. When I go to update a record the dropdown does not populate with the value of the current record.

I understand how to set the selectedvalue, but i dont understand how to retrieve the records value for this field to set the selectedvalue to.

This is my code that isnt working. Any help is appreciated.

ASPX Code:
<telerik:GridDropDownColumn DataSourceID="ReportFormatddlist" ListTextField="ReportFormat"
    ListValueField="ReportFormat" UniqueName="ddReportFormat" SortExpression="ReportFormat"
    HeaderText="Report Format" DropDownControlType="DropDownList" DataField="ReportFormat">
</telerik:GridDropDownColumn>


.VB Code:
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
    If (TypeOf e.Item Is GridEditableItem AndAlso CType(e.Item, GridEditableItem).IsInEditMode) Then
 
        'Report Render Format. The 3 values are just plugged into a list
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
        Dim editMan As GridEditManager = editedItem.EditManager
        Dim editor As GridDropDownListColumnEditor = CType(editMan.GetColumnEditor("ddReportFormat"), GridDropDownListColumnEditor)
        Dim ReportFormatddList As DropDownList = editor.DropDownListControl
 
        'populate the list
        ReportFormatddList.Items.Insert(0, New ListItem("Excel", "Excel"))
        ReportFormatddList.Items.Insert(1, New ListItem("PDF", "PDF"))
        ReportFormatddList.Items.Insert(2, New ListItem("HTML4.0", "HTML4.0"))
        ReportFormatddList.DataBind()
 
        'prime value for update
           '**this is where I am having trouble**
        Dim ReportFormatEditor As GridDropDownListColumnEditor = editMan.GetColumnEditor("ddReportFormat")
        Dim ReportFormatValue = ReportFormatEditor.SelectedText
        editor.SelectedText = ReportFormatValue.ToString
 
        'Report name. The values are pulled from the db.
        editor = CType(editMan.GetColumnEditor("ddReportName"), GridDropDownListColumnEditor)
        editor.DataSource = (From r In DbContext.SubscriptionReportNames Select r).ToList()
        editor.DataBind()
 
    End If
End Sub

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Jun 2012, 05:31 PM
Hello Justin,

  <MasterTableView DataKeyNames="ID" >
.................
.................
<telerik:GridDropDownColumn UniqueName="ddReportFormat" HeaderText="Report Format"
                        DropDownControlType="DropDownList" DataField="ID">
                    </telerik:GridDropDownColumn>

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem item = e.Item as GridEditableItem;
              
               
                GridEditManager manager = item.EditManager;
                GridDropDownListColumnEditor dde = manager.GetColumnEditor("ddReportFormat") as GridDropDownListColumnEditor;
                DropDownList ReportFormatddList  = dde.DropDownListControl;
                ReportFormatddList.Items.Insert(0,new ListItem("0","0"));
                ReportFormatddList.Items.Insert(1, new ListItem("1", "1"));
 
 
                string strID = item.GetDataKeyValue("ID").ToString();
                if (!string.IsNullOrEmpty(strID) && ReportFormatddList.Items.FindByValue(strID) != null)
                {
                    ReportFormatddList.Items.FindByValue(strID).Selected = true;
                }
            }
 
        }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
justin
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or