我想刪除網格視圖中的行,這是我在rowcommand中的後端代碼。 我已經創建了一個OnRowDeleting,但函數中沒有任何內容。在gridview中刪除一行獲取錯誤
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.NotSupportedException' 類型的異常出現在 System.Web.dll中,但未在用戶代碼中處理
附加信息:刪除不受數據源支持除非指定了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"
>
plz用數據源更新前端代碼 – Chandru
谷歌會給你第一個搜索結果本身的解決方案,你用過它。 – niksofteng
@Chandru嗨,即時更新 – Jan