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

Dropdown In Rad Grid Update Mode

1 Answer 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
avinob
Top achievements
Rank 1
avinob asked on 14 Jan 2009, 08:54 PM
Hi

I am using rad grid to show register user data. In the edit mode i have two drop down one for country and another for role.
First : I need to have "----Select----" on top of both the drop down. I used
             DropDownList.Items.Insert(0, New ListItem("--Select--"))
            But still not able to achive the result
sec : I need to to make Country drop down enable false on selection change event of role drop down
        how to have an event for Role dropdown selection change and how to access both the drop downs present in Form template of edit mode from an event outside grid.


Thanks
Avinob

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Jan 2009, 04:18 AM
Hi Avinob,

Give a try with the following code snippet to add an item on top of the DropDownList.


ASPX:
  <EditFormSettings EditFormType="Template" >  
                  <FormTemplate> 
                      <asp:DropDownList ID="DropDownList1" runat="server"
                      </asp:DropDownList> 
                      <asp:DropDownList ID="DropDownList2" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"
                       <asp:ListItem Text="Text1" ></asp:ListItem> 
                         <asp:ListItem Text="Text2" ></asp:ListItem> 
                       </asp:DropDownList> 
                  </FormTemplate> 
               </EditFormSettings> 

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditFormItem editFormItem = (GridEditFormItem)e.Item; 
            DropDownList ddl1 = (DropDownList)editFormItem.FindControl("DropDownList1"); 
            DropDownList ddl2 = (DropDownList)editFormItem.FindControl("DropDownList2"); 
            ddl1.Items.Insert(0, "--Select--"); 
            ddl2.Items.Insert(0, "--Select--"); 
        } 
 } 


Try the following code snippet to disable one DropDownControl in the SelectedIndexChanged event of the second DropDownList.

CS:
 protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList ddl2 = (DropDownList)sender; 
        GridEditFormItem editform = (GridEditFormItem)ddl2.NamingContainer; 
        DropDownList ddl1 = (DropDownList)editform.FindControl("DropDownList1"); 
        ddl1.Enabled = false
    } 


Here is code snippet to access the controls in an editform from the click event of a button outside the Grid.

CS:
 protected void Button1_Click(object sender, EventArgs e) 
    { 
        foreach (GridEditFormItem editformItem in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)) 
        { 
            if (editformItem.IsInEditMode) 
            { 
                DropDownList ddl1 = (DropDownList)editformItem.FindControl("DropDownList1"); 
                DropDownList ddl2 = (DropDownList)editformItem.FindControl("DropDownList2"); 
            } 
        } 
    } 


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