任何人都知道如何使用模板字段所在的网格视图中已经使用的 SqlDataSource 和使用更新功能的按钮字段来获取文本框的 Templatefield 列,以将键入的数据反馈回 sql 数据库?我只是想知道是否有人知道如何让它工作,因为我无法找到任何方法来做到这一点。
如果你们中的任何人需要更多信息来帮助您解决这个难题,请告诉我。
如果我启用编辑和更改文本框中的信息以及同一行中的另一列字段,我可以将信息反馈到 SQL 服务器,但如果我只更改信息,它不会更新文本框是否处于编辑模式或只是单击更新按钮。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<center>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Brdcst_Nbr" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display." Width="657px">
<Columns>
<asp:BoundField DataField="Brdcst_Nbr" HeaderText="Brdcst_Nbr" ReadOnly="True"
SortExpression="Brdcst_Nbr" />
<asp:BoundField DataField="Item_Nbr" HeaderText="Item_Nbr"
SortExpression="Item_Nbr" ReadOnly="True" />
<asp:CheckBoxField DataField="IsPicked" HeaderText="IsPicked"
SortExpression="IsPicked" />
<asp:TemplateField SortExpression="Row" HeaderText="Row">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Mode="twoway" AutoPostBack="true" CausesValidation="true" Text='<%# Bind("Row") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Mode="twoway" AutoPostBack="true" CausesValidation="true" Text='<%# Bind("Row") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" CommandName="Update" Text="Update" />
<asp:ButtonField ButtonType="Button" CommandName="Edit" Text="Edit" />
</Columns>
<EditRowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ORDCConnectionString1 %>"
DeleteCommand="DELETE FROM [Test_New_Transpick] WHERE [Brdcst_Nbr] = @original_Brdcst_Nbr AND (([Item_Nbr] = @original_Item_Nbr) OR ([Item_Nbr] IS NULL AND @original_Item_Nbr IS NULL)) AND [IsPicked] = @original_IsPicked AND (([Row] = @original_Row) OR ([Row] IS NULL AND @original_Row IS NULL))"
InsertCommand="INSERT INTO [Test_New_Transpick] ([Brdcst_Nbr], [Item_Nbr], [IsPicked], [Row]) VALUES (@Brdcst_Nbr, @Item_Nbr, @IsPicked, @Row)"
UpdateCommand="UPDATE [Test_New_Transpick] SET [IsPicked] = @IsPicked, [Row] = @Row WHERE [Brdcst_Nbr] = @original_Brdcst_Nbr"
OldValuesParameterFormatString="original_{0}"
ProviderName="<%$ ConnectionStrings:ORDCConnectionString1.ProviderName %>"
SelectCommand="SELECT * FROM [Test_New_Transpick]" >
<DeleteParameters>
<asp:Parameter Name="original_Brdcst_Nbr" Type="String" />
<asp:Parameter Name="original_Item_Nbr" Type="String" />
<asp:Parameter Name="original_IsPicked" Type="Boolean" />
<asp:Parameter Name="original_Row" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Brdcst_Nbr" Type="String" />
<asp:Parameter Name="Item_Nbr" Type="String" />
<asp:Parameter Name="IsPicked" Type="Boolean" />
<asp:Parameter Name="Row" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Item_Nbr" Type="String" />
<asp:Parameter Name="IsPicked" Type="Boolean" />
<asp:Parameter Name="Row" Type="String" />
<asp:Parameter Name="original_Brdcst_Nbr" Type="String" />
<asp:Parameter Name="original_Item_Nbr" Type="String" />
<asp:Parameter Name="original_IsPicked" Type="Boolean" />
<asp:Parameter Name="original_Row" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</center>
</body>
</html>