[英]Delete row in gridview get error
我想在網格視圖中刪除行,這是來自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>
單擊刪除按鈕時出現此錯誤
System.Web.dll中發生類型'System.NotSupportedException'的異常,但未在用戶代碼中處理
附加信息:除非指定DeleteCommand,否則數據源'SqlDataSource2'不支持刪除。
數據源
<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"
>
您必須將CommandName設置為“刪除”,例如插入“刪除”:
<asp:ButtonColumn CommandName="Delete" Text="Delete"></asp:ButtonColumn>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.