小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

GridView.RowDeleting?事件

 suweixin 2011-01-15

GridView.RowDeleting 事件

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

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

    微軟的MSDN上面提供了相應(yīng)的事件介紹,還有事例程序代碼,可是即使我按照上面的代碼寫,依然還是這個(gè)錯(cuò)誤,好像根本找不到我定義的函數(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ù)源的方式,而是采用動(dòng)態(tài)綁定數(shù)據(jù)的。看來不完全用微軟的東西就會(huì)出問題啊,微軟太霸道了。網(wǎng)上的回帖大多都是不了了之,也不知道孰是孰非,反正覺得有用的都記下來吧,也許我真的是犯了很小的錯(cuò)誤,就像下面的朋友一樣,忘了注冊(cè)一下而已。

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

②處理方法有2種:
(1)如果你不需要這個(gè)事件,那么刪除
GridView2.RowDeleting += .....
這一行.
(2)如果需要這個(gè)事件,則添加處理該事件的方法,
方法的具體格式去查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”就可以了。因?yàn)樵撝担?#8220;delete”)是微軟的默認(rèn)值,它默認(rèn)會(huì)觸發(fā)RowDeleting事件。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多