我已经为书店制作了网页,在这个页面中我有网格视图从SQL DB读取书籍信息和QTY,然后员工可以选择所请求的行。 选定的行将被复制到生成的网格视图,然后在完成订单后有保存按钮将订单发送到DB。
到目前为止,每件事都做得很好, 但是在DB员工中保存日期之前需要更新所请求的QTY字段。 所以更新按钮应该更改值,然后将其保存在DB中。在保存结果之前,如何在不连接到DB的情况下更新行的任何想法?
下面的是代码的一部分:
GridView1将从数据库中读取书籍信息:
<asp:GridView ID="gvAll" runat="server" EmptyDataText="No files found!" OnPageIndexChanging = "OnPaging" >
<Columns><asp:BoundField DataField="ID" HtmlEncode = "false"/>
<asp:BoundField DataField="BookName" HtmlEncode = "false" />
<asp:BoundField DataField="LangName" HtmlEncode = "false"/>
<asp:BoundField DataField="ClassName" HtmlEncode = "false"/>
<asp:BoundField DataField="Total" HtmlEncode = "false" />
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" onclick = "checkAll(this);"
AutoPostBack = "true" OnCheckedChanged = "CheckBox_CheckChanged"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" onclick = "Check_Click(this)"
AutoPostBack = "true" OnCheckedChanged = "CheckBox_CheckChanged" />
</ItemTemplate>
GridViews2将从gridview1接收行:
<asp:GridView ID="gvSelected" runat="server" EmptyDataText="No files found!"
AutoGenerateColumns="False" Font-Names="Verdana" AllowPaging="True"
Width="796px" CellPadding="4" ForeColor="#333333" GridLines="None"
AllowSorting="True" style="text-align: center" >
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" BorderColor="#CCCCCC" BorderStyle="Solid" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BorderColor="#CCCCCC" BorderStyle="Solid" BackColor="#E3EAEB" />
<Columns>
<asp:BoundField DataField="ID" > </asp:BoundField>
<asp:BoundField DataField="BookName" > </asp:BoundField>
<asp:BoundField DataField="LangID" > </asp:BoundField>
<asp:BoundField DataField="ClassID" > </asp:BoundField>
<asp:BoundField DataField="Total" > </asp:BoundField>
<asp:BoundField DataField="Total" />
</Columns>
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
<asp:Button ID="btn_insert" runat="server" onclick="btn_insert_Click" Text="Save Rows" />
现在在Cs页面中,我有一些相关的代码,用于将两个Grid之间的行复制为数组。
并且btn_insert与数据库有连接以保存结果:
SqlConnection con = new SqlConnection(connectionStrinrg);
SqlCommand com = new SqlCommand("insert into Table(Field1,Field2,Field3,Field4,QTY) values ('" + g1.Cells[0].Text + "','" + g1.Cells[1].Text + "','" + g1.Cells[2].Text + "','" + g1.Cells[3].Text + "','" + g1.Cells[4].Text + "')", con);
上述规则将从Gridview2插入结果我想更新字段&#34; QTY&#34;之前将其发送给DB。