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

[Solved] Grid with dropdown list

1 Answer 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
naveen veda
Top achievements
Rank 1
naveen veda asked on 11 Jun 2009, 06:19 AM
Hi,

I am using radgrid for asp.net.

in that grid i need to fill dropdown list within the item template through code behind.

my problem is the data for the dropdown list is changed for each row.

how can i fill the dropdown list with different data for each row?

pls give me the suggestion.


thanks,

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Jun 2009, 07:00 AM
Hi Naveen,

Try the following code snippet.

ASPX:
 
  . . . 
<rad:GridTemplateColumn UniqueName="Dropdown"
    <ItemTemplate> 
        <asp:DropDownList ID="DropDownList1" runat="server"
        </asp:DropDownList> 
    </ItemTemplate> 
</rad:GridTemplateColumn> 
<rad:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" SortExpression="EmployeeID" UniqueName="EmployeeID"
</rad:GridBoundColumn> 
  . . . 

CS:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        GridDataItem item = (GridDataItem) e.Item; 
        if (item["EmployeeID"].Text == "1")  // Checking for condition - row1 
        { 
            DropDownList dropdown = (DropDownList)item.FindControl("DropDownList1"); 
            dropdown.Items.Add("Item for 11"); 
            dropdown.Items.Add("Item for 12"); 
            dropdown.Items.Add("Item for 13"); // Populate dropdown 
        } 
        else if (item["EmployeeID"].Text == "2"// Checking for condition 
        { 
            DropDownList dropdown = (DropDownList)item.FindControl("DropDownList1"); 
            dropdown.Items.Add("Item for 21"); 
            dropdown.Items.Add("Item for 22"); 
            dropdown.Items.Add("Item for 23"); // Populate dropdown 
        } 
    } 

-Shinu.
Tags
Grid
Asked by
naveen veda
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or