events - How to change the functionality of button as well as text of it -


i have createuser page in have field , submit button.

when click on submit button save details database

aspx.cs code createuser page:

 protected void btnsubmit_click(object sender, eventargs e) {     using (sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["webgallery"].tostring()))     {         con.open();         sqldataadapter da = new sqldataadapter();         datatable dt = new datatable();          string strsql = "select * newuser username = '" + tbname.text + "'";          da.selectcommand = new sqlcommand(strsql);         da.selectcommand.connection = con;         da.fill(dt);          if (dt.rows.count > 0) // means first name present         {             lblmsg.text = "this user added!";         }         else if (dt.rows.count == 0)         {             lblmsg.visible = false;             string username = tbname.text;             string pwd=tbpassword.text;             string confirmpwd = tbconfirmpassword.text;             string email = tbemailid.text;             string department = ddldepartment.selectedvalue;             using (sqlcommand cmd = con.createcommand())             {                 cmd.commandtext = "insert newuser(username,password,confirmpassword,emailid,departmentname)values('" + tbname.text + "','" + tbpassword.text + "','"+tbconfirmpassword.text+"','" + tbemailid.text + "','" + ddldepartment.selectedvalue + "')";                 cmd.parameters.addwithvalue("@firstname", tbname.text.trim());                 cmd.parameters.addwithvalue("@lastname", tbpassword.text.trim());                 cmd.parameters.addwithvalue("@domainid", tbconfirmpassword.text.trim());                 cmd.parameters.addwithvalue("@emailid", tbemailid.text.trim());                 cmd.parameters.addwithvalue(@"roletype", ddldepartment.selectedvalue);                 cmd.executenonquery();             }             con.close();             tbname.text = "";             tbpassword.text = "";             tbconfirmpassword.text = "";             tbemailid.text = "";             tbname.focus();         }     } } 

now have search user page in have textbox, gridview , search button when enter name of user , click on search button show user details inside gridview have edit link inside gridview want when click on edit link redirect createuser page in place of submit button want show update button , when make changes , click on update button details selected user select edit link of search user page update. how can

aspx page of search user

<asp:gridview id="gridview1" runat="server" cellpadding="4" forecolor="#333333"              gridlines="none">             <alternatingrowstyle backcolor="white" />            <columns>                 <asp:hyperlinkfield datanavigateurlfields="id"                  datanavigateurlformatstring="~/createuser.aspx?id={0}"                  headertext="edit" navigateurl="~/createuser.aspx" text="edit"/>             </columns>             <editrowstyle backcolor="#2461bf" />             <footerstyle backcolor="#507cd1" font-bold="true" forecolor="white" />             <headerstyle backcolor="#507cd1" font-bold="true" forecolor="white" />             <pagerstyle backcolor="#2461bf" forecolor="white" horizontalalign="center" />             <rowstyle backcolor="#eff3fb" />             <selectedrowstyle backcolor="#d1ddf1" font-bold="true" forecolor="#333333" />             <sortedascendingcellstyle backcolor="#f5f7fb" />             <sortedascendingheaderstyle backcolor="#6d95e1" />             <sorteddescendingcellstyle backcolor="#e9ebef" />             <sorteddescendingheaderstyle backcolor="#4870be" />         </asp:gridview> 

aspx.cs code:

protected void bindgrid() {     if ((tbsearchuser.text.length == 0))     {         lblmessage.text = "search box cannot empty! please put search.";     }     con.open();     string query = "select * newuser username like'" + tbsearchuser.text + "'";     da = new sqldataadapter(query, con);     dataset ds = new dataset();     da.fill(ds);     gridview1.datasource = ds;     gridview1.databind();     gridview1.dispose();     con.close(); } protected void btnsearchuser_click(object sender, eventargs e) {     this.bindgrid(); } 

now have edit link inside gridview want when click on edit link redirect createuser page in place of submit button want show update button , when make changes , click on update button details selected user select edit link of search user page update. how can that?

this have done work me guess work guys well

on create user page user request.querystring this

protected void page_load(object sender, eventargs e) {      if (!ispostback)     {         if (!string.isnullorempty(request.querystring["buttonvalue"]))         {                 string btnvalue = request.querystring["buttonvalue"];                 if (btnvalue == "update")                 {                     btnsubmit.text = "update";                 }                 else if (btnvalue == "submit")                 {                     btnsubmit.text = "submit";                 }                 else                 {                     response.write("error");                 }         }             else         {                 this.btnsubmit.text = "submit";         }          string id = request.querystring["id"];         cmd = new sqlcommand("select * newuser id='" + id + "'", con);         con.open();         da = new sqldataadapter(cmd);         dt.clear();         da.fill(dt);         if (dt.rows.count > 0)         {             tbid.text = id;             tbname.text = dt.rows[0][1].tostring();             tbpassword.text = dt.rows[0][2].tostring();             tbconfirmpassword.text = dt.rows[0][3].tostring();             tbemailid.text = dt.rows[0][4].tostring();             ddldepartment.selectedvalue = dt.rows[0][5].tostring();         }     }     con.close(); } 

and on clik event of button:

protected void btnsubmit_click(object sender, eventargs e) {     if (this.btnsubmit.text == "submit")     {         this.submit();         //response.write("submit");     }     else if (btnsubmit.text == "update")     {         this.update();         //response.write("update");     } } 

in submit function insert query work , update function update query work

and on search page in gridview make changes in hyperlink this

 <asp:hyperlinkfield datanavigateurlfields="id" headertext="edit"                 datanavigateurlformatstring="~/createuser.aspx?id={0}&buttonvalue=update"                navigateurl="~/createuser.aspx" text="edit" /> 

and work me


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -