c# - Selectedindexchanged does not show in the Web -
i have dropdownlist
whenever data selected ddl, autofills textboxes specified.
it values not show in web.
here asp.net
<table class="col-lg-12" align="center" width="900"> <tr> <td align="center" class="style2" valign="middle"> name </td> <td align="center" class="style4" valign="middle"> productid </td> <td align="center" class="style4" valign="middle"> price </td> <td align="center" class="style4" valign="middle"> quantity </td> </tr> <itemtemplate> <tr> <td class="style3"> <asp:dropdownlist id="ddlname" runat="server" class="form-control" autopostback="true" onselectedindexchanged="ddlname_selectedindexchanged" width="200px"> </asp:dropdownlist> </td> <td class="style5"> <asp:label id="lbid" runat="server" width="200px"></asp:label> </td> <td class="style5"> <asp:label id="lbprice" runat="server" width="200px"></asp:label> </td> <td class="style5"> <asp:textbox id="quantity" runat="server" width="200px"></asp:textbox> </td> <td> <asp:button id="addproduct" runat="server" style="color:white" text="add product" width="200px" onclick="addproduct_click" /></td> </tr> </itemtemplate>
ddlselectedindexchanged codes
protected void ddlname_selectedindexchanged(object sender, eventargs e) { string name = ddlname.selecteditem.value; con.open(); sqlcommand cmd = new sqlcommand(); cmd.connection = con; cmd.commandtext = "select name, productid, price products name=@name"; cmd.parameters.addwithvalue("@name", ddlname.selectedvalue); sqldatareader dr = cmd.executereader(); if (dr.hasrows) { dr.read(); int32 lbid = dr.getint32(1); decimal lbprice = dr.getdecimal(2); } }
it doesn't fill textboxes. sorry low profile question. huhuhu help
i believe should assign labels instead:
lbid.text = dr.getint32(1).tostring(); lbprice.text = dr.getdecimal(2).tostring();
alternatively recommend looking detailsview control more elegant, , easier in cases, solution: detailsvew web server control
Comments
Post a Comment