日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

GridView.RowDeleting?事件

 suweixin 2011-01-15

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ǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多