如何在单击“更新”时更新行?按钮在web应用程序gridview
本文关键字:更新 按钮 应用程序 gridview web 单击 | 更新日期: 2023-09-27 18:04:48
在我的web应用程序ASP。. NET,我到目前为止已经配置了一个gridview,在那里我可以删除行(我有一个主身份(1,1)键集)并单击"编辑"按钮以获得可编辑的行,但我不知道如何获得行更新。
基本上,在用户编辑web应用程序的gridview中的文本框后,我不确定如何获取该数据,并在VB中编写代码。. NET附加到数据库。
这是我的HTML代码的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] AS Commission_Earned, [Commission Rate] AS Commission_Rate, [MSRP], [Sale Price] AS Sale_Price, [Salesperson], [VIN] FROM [Sales]"
DeleteCommand="SELECT * FROM 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>
与其添加3个不同的按钮,不如这样写:
<asp:CommandField ShowEditButton="True" UpdateText="Update" EditText="Update" CancelText="Cancel" ControlStyle-CssClass="btn btn-blue" />
填充方法
UpdateCommand="UPDAE [Table] SET Salesperson=@Salesperson"