Click here to Skip to main content
15,038,451 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I added one column to gridview that is Dropdownlist
<asp:TemplateField HeaderText="ramesh" >
          <asp:DropDownList ID="ddlName"  DataTextField="job_desc"
                  Width="100" runat="server">

How to bind datatable column to that Gridview DropDownList list.
Updated 7-May-10 4:08am

1 solution

Here you go:
Nesting the DropDownList to Gridview in ASP.NET 2.0(C#)[^]

It would be something like:
if (e.Row.RowType == DataControlRowType.DataRow)
categoryid = Int32.Parse(e.Row.Cells[0].Text);
expression = "categoryid = " + categoryid;
DropDownList ddl = (DropDownList)e.Row.FindControl("dropdownlist1");
DataRow[] rows = ds.Tables[0].Select(expression);

foreach (DataRow row in rows)
DataRow newrow = mytable.NewRow();
newrow["productid"] = row["productid"];
newrow["productname"] = row["productname"];
ddl.DataSource = mytable;
ddl.DataTextField = "productname";
ddl.DataValueField = "productid";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900