Cannot get the SelectedValue of the Drop Down List ASP.NET -


ok, when want selectedvalue of dropdownlist when click button, selectedvalue return "" (nothing), please me thanks!

here source

    <tr>     <th style="float:left">     <asp:dropdownlist id="ddlcategory" runat="server" ></asp:dropdownlist>     <asp:textbox id="txtsearch" runat="server"></asp:textbox>     <asp:imagebutton id="btnsearch" runat="server" height="20px" imageurl="~/img/search.png" onclick="btnsearch_click" width="20px" />     <asp:linkbutton id="lbtnsearch" runat="server" postbackurl="~/search.aspx">advanced search</asp:linkbutton>     </th>     </tr> 

and here code behind

    public partial class _default : system.web.ui.page {     sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["connectionstring"].connectionstring);     sqldataadapter adapter = new sqldataadapter();      protected void page_load(object sender, eventargs e)     {         if (!ispostback)         {             binddatalist();             binddropdown();         }     }      private void binddatalist()     {         string cmd = "select top 3 product_id, product_name, brand, imgurl product order newid()";         adapter.selectcommand = new sqlcommand(cmd, con);         datatable dt = new datatable();         adapter.fill(dt);         datalist1.datasource = dt;         datalist1.databind();     }      private void binddropdown()     {         string cmd = "select category_id, category_name category";         adapter.selectcommand = new sqlcommand(cmd, con);         datatable dt = new datatable();         adapter.fill(dt);         ddlcategory.datatextfield = "category_name";         ddlcategory.datavaluefield = "category_id";         ddlcategory.datasource = dt;         ddlcategory.databind();     }      protected void btnsearch_click(object sender, imageclickeventargs e)     {         response.redirect("~/product/product.aspx?category_id=" + ddlcategory.selectedvalue.tostring() + "&search=" + txtsearch.text);     } } 

and result when click btnsearch "http://localhost:1345/product/product.aspx?category_id=&search=something" can see that ddlcategory.selectedvalue.tostring() return "", what's wrong?

damn, spent hours, , solve problem. problem enableviewstate set false in master page (the parent control). , need set true. if dropdownlist (child control) enabled viewstate, need determine on parent control. i.e. enableviewstate in parent control set false, child control false.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -