asp.net - Insert data into Database from grid view & delete textbox values in gridview -


i had problem when insert db textbox values grid view, command true button, may know how delete texbox value in grid view without using db ? kindly advise, thank you.

       <asp:label id="label1" runat="server" text="name"></asp:label>     <asp:textbox id="txtname" runat="server"></asp:textbox>     <asp:label id="address" runat="server" text="label"></asp:label>     <asp:textbox id="txtaddress" runat="server"></asp:textbox>     <asp:button id="button1" runat="server" onclick="button1_click" text="add" />     <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false">         <columns>             <asp:boundfield datafield="name" headertext="name" />             <asp:boundfield datafield="address" headertext="adress" />              <asp:commandfield buttontype="button" showdeletebutton="true" causesvalidation="false" />          <asp:button id="button2" runat="server" onclick="button2_click" text="submit" />         </columns>     </asp:gridview> 

code behind

  protected void page_load(object sender, eventargs e)     {           if (!ispostback)         {             datatable table = new datatable();             table.columns.add("name", typeof(string));             table.columns.add("address", typeof(string));             session["value"] = table;         }      }      protected void button1_click(object sender, eventargs e)     {         datatable dt = (datatable)session["value"];         dt.rows.add(txtname.text, txtaddress.text);         gridview1.datasource = dt;         gridview1.databind();     }        protected void button2_click(object sender, eventargs e)     {          sqlconnection con = new sqlconnection(system.configuration.configurationmanager.connectionstrings["cimprorpt01connectionstring"].connectionstring);         string sql = "insert details (name,address) values ('@name','@address')";         sqlcommand cmd = new sqlcommand(sql, con);         con.open();         cmd.executenonquery();          con.close();         datatable dt = (datatable)session["value"];         dt.rows.add(txtname.text, txtaddress.text);           gridview1.datasource = dt;         gridview1.databind();     }     } 

}


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -