虽然我在删除事件中删除了一行,但我希望从GridView
获得brandid。
我该怎么做?
<asp:GridView ID="GridView1" OnRowDeleted="GridView1_RowDeleted" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="brandname" HeaderText="brandname" SortExpression="brandname" />
<asp:BoundField DataField="info" HeaderText="info" SortExpression="info" />
<asp:ButtonField DataTextField="brandname" HeaderText="brandname" ButtonType="Button"/>
<asp:BoundField DataField="Id" HeaderText="brandid" ReadOnly="True" SortExpression="Id" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" DeleteCommand="DELETE FROM [brand_tbl] WHERE [Id] = @original_Id AND (([brandname] = @original_brandname) OR ([brandname] IS NULL AND @original_brandname IS NULL)) AND (([info] = @original_info) OR ([info] IS NULL AND @original_info IS NULL))" InsertCommand="INSERT INTO [brand_tbl] ([brandname], [info]) VALUES (@brandname, @info)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [brand_tbl]" UpdateCommand="UPDATE [brand_tbl] SET [brandname] = @brandname, [info] = @info WHERE [Id] = @original_Id AND (([brandname] = @original_brandname) OR ([brandname] IS NULL AND @original_brandname IS NULL)) AND (([info] = @original_info) OR ([info] IS NULL AND @original_info IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_brandname" Type="String" />
<asp:Parameter Name="original_info" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="brandname" Type="String" />
<asp:Parameter Name="info" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="brandname" Type="String" />
<asp:Parameter Name="info" Type="String" />
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_brandname" Type="String" />
<asp:Parameter Name="original_info" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
答案 0 :(得分:2)
在您的RowDeleted事件中,您只需抓取e.Keys["Id"].ToString()
即可获得品牌ID的值。这是有效的,因为你已经定义了&#34; Id&#34;作为GridView的datakeynames值。
protected void GridView1_RowDeleted (Object sender, GridViewDeletedEventArgs e)
{
string brandId = e.Keys["Id"].ToString();
}
答案 1 :(得分:0)
请将此检查到您的代码中
<强>即rowindex显示为已删除事件中行的ID