Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
my code is
C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!Page.IsPostBack)
       {
           DataSet ds = getdata();
           StringBuilder sb = new StringBuilder();
           sb.AppendLine("<table>");
           sb.AppendLine("<tr>");
           sb.Append("<td>");
           sb.Append("<select id='drp1'>");
           sb.Append("<option value='0'> select </option>");
           for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
           {
    sb.Append("<option value='" + ds.Tables[0].Rows[i]["id"].ToString() + "'> " + ds.Tables[0].Rows[i]["name"].ToString() + "</option>");              

           }
           sb.Append("</select>");
           sb.AppendLine("</table>");
           sb.AppendLine("</tr>");
           sb.Append("</td>");
           d1.InnerHtml = sb.ToString();
           var page = (Context.Handler as System.Web.UI.Page);
       }
   }
   public DataSet getdata()
   {
       using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ToString()))
       {
           SqlDataAdapter da = new SqlDataAdapter("select id,name from empdetails", con);
           DataSet ds = new DataSet();
           da.Fill(ds);
           return ds;
       }
   }
   protected void btnadd_click(object sender, EventArgs e)
   {
       try
       {
          int h = Convert.ToInt32(Request.Form["drp1"]);
       }
       catch (Exception ex)
       {
       }
   }


when i am select any item and click on button ,in button click i wrote the code but it not getting selected value ,its showing in 'h' value is 0(zero).pls i want selected value.how to get pls respond my question .........
Posted
Updated 28-Jul-15 19:43pm
v2
Comments
Suvendu Shekhar Giri 29-Jul-15 1:46am    
Why this much of hard work when you can have way better control with asp dropdownlist?

1 solution

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