我想删除网格视图中的行,这是我在rowcommand中的后端代码。 我已经在函数中创建了一个OnRowDeleting但没有任何内容。
protected void grid2_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName) // check the incoming command name
{
case "remove":
if (grid2.Rows.Count > 1)
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
//GridViewRow row = (GridViewRow)grid2.Rows[rowIndex];
grid2.DeleteRow(rowIndex); //error pointing to this
grid2.DataBind();
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "
<script>alert('Last row');</script>");
}
break;
}
我的前端代码
<ItemTemplate>
<asp:Button ID="BtnDelete" runat="server" Text="Delete"
CssClass="btn btn-primary" CommandName="remove" CommandArgument='<%# Container.DataItemIndex %>'/>
</ItemTemplate>
当我点击删除按钮
时出现此错误类型&#39; System.NotSupportedException&#39;的例外情况发生在 System.Web.dll但未在用户代码中处理
其他信息:数据源不支持删除 &#39; SqlDataSource2&#39;除非指定了DeleteCommand。
数据源
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStr_epsi %>"
ProviderName="<%$ ConnectionStrings:ConnStr_epsi.ProviderName %>" SelectCommand=""></asp:SqlDataSource>
我的网格
<grd:MultiSelectGridView ID="grid2" runat="server" Width="500px"
CssClass="paging_gridview" AllowPaging="True"
AutoGenerateColumns ="false" PageSize="10" PagerType="Custom"
ShowFooter="true" OnRowDeleting="grid2_RowDeleting"
MultiSelectDataKeyName="Urid,Name" ShowHeaderWhenEmpty="true"
MultiSelectColumnIndex="0" EnableMultiSelect="false" GridLines="None" BorderStyle="None" OnRowCommand="grid2_RowCommand"
>