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

[Solved] RadGrid Edit Mode Dropdownliast binding

1 Answer 249 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shehab
Top achievements
Rank 1
Shehab asked on 23 Jun 2008, 12:02 PM
Hello everyone,

I am running into a RadGrid and binding the datasource for it programmatically, one of the columns should be a dropdown list so when I am in edit mode it would query a table and show options to choose from
                          <radG:GridTemplateColumn DataField="DepName" HeaderText="DepName" UniqueName="DepName">  
                                <ItemTemplate> 
                                    <asp:DropDownList ID="lblDep" runat="server" Enabled="false" /> 
                                </ItemTemplate> 
                                <EditItemTemplate> 
                                    <asp:DropDownList ID="DepNameddl" runat="server" /> 
                                </EditItemTemplate> 
                          </radG:GridTemplateColumn> 
 
 And here is the ItemDataBound that I can't seem to get to work;
    Protected Sub rgPersonAdmin_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.WebControls.GridItemEventArgs) Handles rgPersonAdmin.ItemDataBound  
        If TypeOf e.Item Is GridDataItem Then 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
            Dim strChk As String = item.GetDataKeyValue("PersonIndic").ToString()  
            Dim chkbx As CheckBox = DirectCast(item("PersonIndic").FindControl("cbPersonIndic"), CheckBox)  
            If strChk = "1" Then 
                chkbx.Checked = True 
            Else 
                chkbx.Checked = False 
            End If 
 
            'dropdownlist  
            Dim ddl As DropDownList = DirectCast(item("DepName").FindControl("lblDep"), DropDownList)  
            Dim getDS As New DataSet  
            getDS = dataConn.PhoneGetDepDDL()  
            ddl.DataSource = getDS.Tables(0).DefaultView  
            ddl.DataTextField = "DepName" 
            ddl.DataValueField = "DepID" 
            ddl.DataBind()  
 
        End If 
    End Sub 
 
It works fine to bind the checkbox but it is not working for the dropdownlist.

I saw in other forms about the gridColumnDropDownList but I couldn't find a way to bind it programmatically; any help will be appreciated.

Thanks,
Shehab

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jun 2008, 12:35 PM
Hi Shehab,

Try accessing the DropDownList in edit mode as shown below.

CS:
 protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
          
        if((e.Item is GridEditableItem)&&(e.Item.IsInEditMode))  
        {  
            GridEditableItem edititem = (GridEditableItem)e.Item;  
            DropDownList ddl = (DropDownList)edititem["DepName"].FindControl("DepNameddl");  
        }  
   } 


Thanks
Princy.
Tags
Grid
Asked by
Shehab
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or