c# - How to bind Gridview update with Object Datasource parameters -


i have gridview shopping cart columns

id | productname | productprice | productquantity | totalprice  

quantity editable column in gridview. need pass id , quantity datasource , how can that? beginner , have been working on hour , appreciated

.aspx file

   <asp:objectdatasource id="objectdatasource1" runat="server" selectmethod="getlistfromcart" typename="getfromcart" deletemethod="deletelistfromcart" updatemethod="updatelistfromcart"  >         <deleteparameters>             <asp:parameter name="id" type="int32" />         </deleteparameters>         <updateparameters>             <asp:parameter name="id" type="int32" />             <asp:parameter name="quantity" type="int32" />          </updateparameters>         </asp:objectdatasource>      <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" datasourceid="objectdatasource1" cellpadding="10" cellspacing="2" >         <columns>              <asp:commandfield showdeletebutton="true" showeditbutton="true" />             <asp:boundfield datafield="id" headertext="id" sortexpression="id" readonly="true" />             <asp:boundfield datafield="productname" headertext="productname" sortexpression="productname" readonly="true" />             <asp:boundfield datafield="productprice" headertext="productprice" sortexpression="productprice" readonly="true" />             <asp:templatefield headertext="quantity" sortexpression="quantity">                 <edititemtemplate>                     <asp:textbox id="textbox1" runat="server" text='<%# bind("quantity") %>'></asp:textbox>                 </edititemtemplate>                 <itemtemplate>                     <asp:label id="label1" runat="server" text='<%# bind("quantity") %>'></asp:label>                 </itemtemplate>             </asp:templatefield>             <asp:boundfield datafield="totalprice" headertext="totalprice" sortexpression="totalprice"  readonly="true" />         </columns>         <editrowstyle horizontalalign="center" />     </asp:gridview> 

.cs file

public static void updatelistfromcart(int id,int quantity) {     using (sqlconnection conn = new sqlconnection(connection))     {         sqlcommand cmd = new sqlcommand("updatecartdetails", conn);         cmd.parameters.add("@id", sqldbtype.int).value = id;         cmd.parameters.add("@quantity", sqldbtype.int).value = quantity;         conn.open();         cmd.executenonquery();         conn.close();     }  } 


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -