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

Get items of RadGrid using for each

1 Answer 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ravi
Top achievements
Rank 1
ravi asked on 08 Dec 2008, 06:43 PM
Hi

How to get the control values using foreach of radgrid in asp.net

here code, i have written like but its giving error
i want to identify form tamplate column control in radgrid.

foreach

(GridEditFormItem item in RadGrid1.MasterTableView.ChildEditItems) { 

 

if(item.ItemType==GridItemType.EditFormItem)  

{

((

DropDownList)item.FindControl("drop2")).Items.Add(new ListItem("Ravi" + ((DropDownList)item.FindControl"drop1")).SelectedValue));  

 

 

}}

plz help give me any suggetions.

thx advance

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Dec 2008, 06:35 AM
Hello Ravi,

I suppose you are trying to populate the second dropdown based on the selected value of the first dropdown both of which are placed in the EditFormTemplate of the grid. If this is the case, check out the code below to achieve the scenario.
aspx:
 <EditFormSettings EditFormType="Template" > 
            <FormTemplate>            
                <asp:DropDownList ID="drop1" AutoPostBack="true"  runat="server" OnSelectedIndexChanged="drop1_SelectedIndexChanged"
                <asp:ListItem Text="Text1" Value="1">                 
                </asp:ListItem>                  
                 <asp:ListItem Text="Text2" Value="2">                 
                </asp:ListItem> 
                </asp:DropDownList>                 
                <asp:DropDownList ID="drop2" runat="server"
                </asp:DropDownList> 
      </FormTemplate>                
 </EditFormSettings> 

cs:
protected void drop1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList ddl1 = (DropDownList)sender; 
        GridEditableItem editItem = (GridEditableItem)ddl1.NamingContainer; 
        DropDownList ddl2 = (DropDownList)editItem.FindControl("drop2");       
        ddl2.Items.Add(new ListItem("Ravi" + (ddl1.SelectedValue))); 
           
    } 

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