Click here to Skip to main content
15,949,741 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
XML
<asp:TemplateField HeaderText="ramesh" >
      <ItemTemplate>
          <asp:DropDownList ID="ddlName"  DataTextField="job_desc"
                  Width="100" runat="server">
          </asp:DropDownList>
       </ItemTemplate>
</asp:TemplateField>

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

1 solution

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

It would be something like:
C#
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"];
mytable.Rows.Add(newrow);
}
ddl.DataSource = mytable;
ddl.DataTextField = "productname";
ddl.DataValueField = "productid";
ddl.DataBind();
}
 
Share this answer
 

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