国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
GridView.RowDeleting?事件

GridView.RowDeleting 事件

(2008-04-22 14:35:15)

    一大早起來編程序,在經(jīng)過慎重選擇之后用HyperLink解決了RowEdit的問題??墒墙又霈F(xiàn)了一個刪除操作的問題,無論我如何修改、設(shè)置,總是提示我:激發(fā)了未處理的事件RowDeleting”。即使我把自帶的CommandField刪除按鈕換作我自己添加的ButtonField刪除按鈕,同樣都定義了RowDeleting事件,可是問題依然如此,反復(fù)出現(xiàn)這樣的提示。

    微軟的MSDN上面提供了相應(yīng)的事件介紹,還有事例程序代碼,可是即使我按照上面的代碼寫,依然還是這個錯誤,好像根本找不到我定義的函數(shù)。

-------------------------------

  void CustomersGridView_RowDeleting(Object sender, GridViewDeleteEventArgs e)
    
    // Cancel the delete operation if the user attempts to remove
    // the last record from the GridView control.
    if (CustomersGridView.Rows.Count <= 1)
          
      e.Cancel = true;
      Message.Text = "You must keep at least one record."           
      
  }

--------------------------------

    google了一下,發(fā)現(xiàn)遇到同樣問題的還是挺多的,基本上情況和我相同,都不是用直接綁定ObjectDataSource數(shù)據(jù)源的方式,而是采用動態(tài)綁定數(shù)據(jù)的??磥聿煌耆梦④浀臇|西就會出問題啊,微軟太霸道了。網(wǎng)上的回帖大多都是不了了之,也不知道孰是孰非,反正覺得有用的都記下來吧,也許我真的是犯了很小的錯誤,就像下面的朋友一樣,忘了注冊一下而已。

①代碼應(yīng)該沒問題,難道事件沒有注冊
<asp:GridView ID="GridView1" runat="server" OnRowDeleting="GridView1_RowDeleting" >

②處理方法有2種:
(1)如果你不需要這個事件,那么刪除
GridView2.RowDeleting += .....
這一行.
(2)如果需要這個事件,則添加處理該事件的方法,
方法的具體格式去查MSDN中關(guān)于RowDeleting的幫助.

③private   void   dgShow_DeleteCommand(object   source,   System.Web.UI.WebControls.DataGridCommandEventArgs   e)
{
if(dgShow.Items.Count==1)
{
if(dgShow.CurrentPageIndex!=0)
dgShow.CurrentPageIndex   =   dgShow.CurrentPageIndex-1;
}
string   strSql   =   "delete   from   tbStudentinfo   where   studentid= "+e.Item.Cells[0].Text+ " ";
ExecuteSql(strSql);
BindData();

}這是刪除的全碼

④如果是用Button刪除的話,這里就是有Button刪除的代碼
private   void   btnDelete_Click(object   sender,   System.EventArgs   e)
{
foreach(DataGridItem   dgi   in   dgShow.Items)
{
CheckBox   cb   =   (CheckBox)dgi.FindControl( "cbSelect ");
if(cb.Checked)
{
//以下執(zhí)行刪除操作
int   nID   =   int.Parse(dgi.Cells[0].Text);
string   strSql   =   "delete   from   tbStudentinfo   where   studentid= "+nID;
ExecuteSql(strSql);
}
}
dgShow.CurrentPageIndex   =   0;
BindData();
}

把下面的代碼

<asp:Button ID="Button3" runat="server" Text="刪除用戶"  CommandArgument='<%#DataBinder.eval_r(Container.DataItem,"UserID") %>' CommandName="delete" />

修改為:

<asp:Button ID="Button3" runat="server" Text="刪除用戶"  CommandArgument='<%#DataBinder.eval_r(Container.DataItem,"UserID") %>' CommandName="del" />  

commandName屬性的值不要等于“delete”就可以了。因為該值(“delete”)是微軟的默認(rèn)值,它默認(rèn)會觸發(fā)RowDeleting事件。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
GridView的RowDeleting、RowUpdating和RowCommand事件...
GridView 刪除記錄的處理提示- 路在何方 - 新浪BLOG
給GridView中的buttonField添加一個刪除確認(rèn)功能
在GridView中添加按鈕后,如何觸發(fā)按鈕的各種事件?
GridView.RowCommand 事件 GridView.DataKeys 屬性
GridView事件
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服