asp.net - Insert values to database table using textbox in gridview -


i have grid view 2 columns. 1 named product , other named values (both columns in template field).

the product column bound "product" table. , value field's item template contains textbox.

i need insert values database table "brandproperties" through textbox in grid view, not sure how this.

here code:

    if (!ispostback)     {         bindview();      }      datatable dt = new datatable();     sqldataadapter da = new sqldataadapter("select id,typename producttypes",con);     da.fill(dt);     dropdownlist1.datasource = dt;     dropdownlist1.datavaluefield = "id";     dropdownlist1.datatextfield = "typename";     dropdownlist1.databind(); }  public void bindview() {      datatable dt = new datatable();     string sql = "select * properties";     con.open();     sqldataadapter da = new sqldataadapter(sql, con);     da.fill(dt);     gridview1.datasource = dt;     gridview1.databind();     con.close(); } 

aspx.code:

   text="brand name"></asp:label>     <asp:button id="button1" runat="server" backcolor="#6699ff"          style="z-index: 1; left: 410px; top: 391px; position: absolute"          text="save" onclick="button1_click" />  <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false"      backcolor="white" bordercolor="#e7e7ff" borderstyle="none" borderwidth="1px"      cellpadding="3" gridlines="horizontal"      style="z-index: 1; left: 52px; top: 230px; position: absolute; height: 133px; width: 344px">     <rowstyle backcolor="#e7e7ff" forecolor="#4a3c8c" />     <columns>         <asp:templatefield headertext="product">             <itemtemplate>                 <asp:label id="label3" runat="server" text='<%# bind("propertyname") %>' ></asp:label>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="value">             <itemtemplate>                 <asp:textbox id="textbox2" runat="server"></asp:textbox>             </itemtemplate>         </asp:templatefield>     </columns> 

try this

    <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false"     backcolor="white" bordercolor="#e7e7ff" borderstyle="none" borderwidth="1px"     cellpadding="3" gridlines="horizontal" style="z-index: 1; left: 52px; top: 230px;     position: absolute; height: 133px; width: 344px">     <rowstyle backcolor="#e7e7ff" forecolor="#4a3c8c" />     <columns>         <asp:templatefield headertext="product">             <itemtemplate>                 <asp:label id="label3" runat="server" text='<%# bind("propertyname") %>'></asp:label>             </itemtemplate>         </asp:templatefield>         <asp:templatefield headertext="value">             <itemtemplate>                 <asp:textbox id="textbox2" runat="server"></asp:textbox>                 <asp:button id="btnsave" runat="server" text="savevalues" onclick = "btnsave_onclick" />             </itemtemplate>         </asp:templatefield>     </columns> </asp:gridview>     protected void btnsave_onclick(object sender, eventargs e) {     button lb = (button)sender;     gridviewrow row = (gridviewrow)lb.namingcontainer;     if (row != null)     {         int index = row.rowindex; //gets row index selected          textbox tb = (textbox)gridview1.rows[index].findcontrol("textbox2");         string yourrequiredtext = tb.text;     } } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -