c# - want to add a new item in my dropdown list thourgh UI such that it added to database as well -
this form in asp.net:
<div> <fieldset> <legend>sign now!!</legend> <table> <tr> <td> <asp:label id="lblusername" runat="server" text="user name"> </asp:label> </td> <td> <asp:textbox id="txtusername" runat="server"></asp:textbox> <asp:requiredfieldvalidator id="rqrdusername" runat="server" text="required" forecolor="red" errormessage="please enter username" controltovalidate="txtusername" validationgroup="signup"> </asp:requiredfieldvalidator> </td> </tr> <tr> <td> <asp:label id="lblfirstname" runat="server" text="first name"> </asp:label> </td> <td> <asp:textbox id="txtfirstname" runat="server"></asp:textbox> <asp:requiredfieldvalidator id="rqrdfirstname" runat="server" text="required" forecolor="red" errormessage="please provide first name" controltovalidate="txtfirstname" validationgroup="signup"> </asp:requiredfieldvalidator> </td> </tr> <tr> <td> <asp:label id="lbllastname" runat="server" text="last name"> </asp:label> </td> <td> <asp:textbox id="txtlastname" runat="server"></asp:textbox> <asp:requiredfieldvalidator id="rqrdlastname" runat="server" text="required" forecolor="red" errormessage="please provide last name" controltovalidate="txtlastname" validationgroup="signup"> </asp:requiredfieldvalidator> </td> </tr> <tr> <td> <asp:label id="lblgender" runat="server" text="gender"> </asp:label> </td> <td> <asp:radiobuttonlist id="rdbtnlst" runat="server"> <asp:listitem>male</asp:listitem> <asp:listitem>female</asp:listitem> </asp:radiobuttonlist> </td> </tr> <tr> <td> <asp:label id="lbldob" runat="server" text="date of birth"> </asp:label> </td> <td> <asp:textbox id="txtdob" runat="server"></asp:textbox></td> </tr> <tr> <td> <asp:label id="lblemail" runat="server" text="email"> </asp:label> </td> <td> <asp:textbox id="txtemail" runat="server" textmode="email"> </asp:textbox> <asp:requiredfieldvalidator id="rqrdemail" runat="server" forecolor="red" errormessage="please provide email address" controltovalidate="txtemail" validationgroup="signup"> </asp:requiredfieldvalidator> </td> </tr> <tr> <td> <asp:label id="lblpassword" runat="server" text="password"> </asp:label> </td> <td> <asp:textbox id="txtpassword" runat="server" textmode="password"> </asp:textbox> <asp:requiredfieldvalidator id="rqrdpassword" runat="server" forecolor="red" errormessage="you must provide password" controltovalidate="txtpassword" validationgroup="signup"> </asp:requiredfieldvalidator> </td> </tr> <tr> <td> <asp:label id="lblconfirmpassword" runat="server" text="confirm password"> </asp:label> </td> <td> <asp:textbox id="txtconfirmpassword" runat="server" textmode="password"> </asp:textbox> <asp:comparevalidator id="matchpassword" runat="server" forecolor="red" errormessage="passwords don't match" controltovalidate="txtconfirmpassword" controltocompare="txtpassword" validationgroup="signup"> </asp:comparevalidator> </td> </tr> <tr> <td></td> <td> <asp:button id="btnsubmit" runat="server" text="submit" onclick="btnsubmit_click" /> </td> <asp:validationsummary id="validationsummary1" runat="server" validationgroup="signup" /> </tr> </table> </fieldset> </div>
this bll:
public void addnewdepartment(string name) { sqlparameter[] param = new sqlparameter[1]; param[0] = new sqlparameter("@dept_name", sqldbtype.varchar); param[0].value = name; objdbconnection = new dbconnection(); objdbconnection.executeinsertprocedure("addnewdepartment", param); } public datatable getdepartments() { objdbconnection = new dbconnection(); string query = "getdepartments"; try { return objdbconnection.executeselectprocedure(query); } catch { return null; } } public datatable getposition() { objdbconnection = new dbconnection(); string query1 = "getposition"; try { return objdbconnection.executeselectprocedure(query1); } catch { return null; } }
this c# class:
public partial class signup : system.web.ui.page { private bll bll; protected void page_load(object sender, eventargs e) { if (!ispostback) { getdepartments(); getposition(); } } protected void btninsert_click(object sender, eventargs e) { bll = new bll(); bll.insertemployee(txtname.text, ddldepartment.text, convert.toint32(txtsalary.text), txtemail.text, ddlposition.text, txtpassword.text, convert.toint32(txtcontactno.text), txtaddress.text); } private void getdepartments() { bll = new bll(); datatable dtdepartments = bll.getdepartments(); ddldepartment.datasource = dtdepartments; ddldepartment.datatextfield = dtdepartments.columns[1].tostring(); ddldepartment.datavaluefield = dtdepartments.columns[0].tostring(); ddldepartment.databind(); } private void getposition() { bll = new bll(); datatable dtposition = bll.getposition(); ddlposition.datasource = dtposition; ddlposition.datatextfield = dtposition.columns[1].tostring(); ddlposition.datavaluefield = dtposition.columns[0].tostring(); ddlposition.databind(); } protected void btnadd_click(object sender, eventargs e) { bll = new bll(); bll.addnewdepartment(txtnewdept.text); ddldepartment.items.add(txtnewdept.text); } } }
i have drop down list in sign-in form department. data source bound database. want add item in database through ui. not inserting item in database. how do that?
Comments
Post a Comment