c# - How do I update rows when clicking "update" button in web application gridview? -
in web application asp.net, far have gridview configured can delete rows (i have primary identity(1,1) key set) , click "edit" button row editable, have no idea how rows update.
basically, after user edits textbox in web application's gridview, i'm not sure how fetch data, , write code in vb.net attach database.
here's html code gridview:
<asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" datakeynames="id" datasourceid="sqldatasource1" width="861px" cellpadding="4" forecolor="#333333" gridlines="none" allowpaging="true" allowsorting="true"> <alternatingrowstyle backcolor="white" /> <columns> <asp:commandfield showeditbutton="true" /> <asp:boundfield datafield="id" headertext="id" sortexpression="id" insertvisible="false" readonly="true" /> <asp:boundfield datafield="commission_earned" headertext="commission_earned" sortexpression="commission_earned" readonly="true" /> <asp:boundfield datafield="commission_rate" headertext="commission_rate" sortexpression="commission_rate" /> <asp:boundfield datafield="msrp" headertext="msrp" sortexpression="msrp" /> <asp:boundfield datafield="sale_price" headertext="sale_price" sortexpression="sale_price" /> <asp:boundfield datafield="salesperson" headertext="salesperson" sortexpression="salesperson" /> <asp:boundfield datafield="vin" headertext="vin" sortexpression="vin" /> <asp:templatefield> <itemtemplate> <asp:linkbutton id="linkbutton1" runat="server" text="delete" commandname="delete" commandargument='<%# eval("id") %>'></asp:linkbutton> <asp:linkbutton id="linkbutton2" runat="server" text="edit" commandname="edit" commandargument='<%# eval("id")%>'></asp:linkbutton> <asp:linkbutton id="linkbutton3" runat="server" text="" commandname="update" onclick = "button1_click" commandargument='<%#eval("salesperson") + "," + eval("vin") + "," + eval("sale_price") + "," + eval("msrp") + "," + eval("commission_rate") %>'></asp:linkbutton> </itemtemplate> </asp:templatefield> </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> <asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:autodealer_matthewbuhrconnectionstring3 %>" selectcommand="select [id], [commission earned] commission_earned, [commission rate] commission_rate, [msrp], [sale price] sale_price, [salesperson], [vin] [sales]" deletecommand="select * sales" updatecommand=""> <updateparameters> <asp:parameter name="id" type="int32" /> <asp:parameter name="salesperson" type="string" /> <asp:parameter name="vin" type="string" /> <asp:parameter name="price" type="string" /> <asp:parameter name="msrp" type="string" /> <asp:parameter name="commissionrate" type="string" /> <asp:parameter name="commissionearned" type="string" /> </updateparameters> </asp:sqldatasource>
insted of adding 3 diffrent buttons, write line:
<asp:commandfield showeditbutton="true" updatetext="update" edittext="update" canceltext="cancel" controlstyle-cssclass="btn btn-blue" />
fill method
updatecommand="updae [table] set salesperson=@salesperson"
Comments
Post a Comment