乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      GridView.RowDeleting?事件

       suweixin 2011-01-15

      GridView.RowDeleting 事件

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

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

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

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

        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ā)現遇到同樣問題的還是挺多的,基本上情況和我相同,都不是用直接綁定ObjectDataSource數據源的方式,而是采用動態(tài)綁定數據的。看來不完全用微軟的東西就會出問題啊,微軟太霸道了。網上的回帖大多都是不了了之,也不知道孰是孰非,反正覺得有用的都記下來吧,也許我真的是犯了很小的錯誤,就像下面的朋友一樣,忘了注冊一下而已。

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

      ②處理方法有2種:
      (1)如果你不需要這個事件,那么刪除
      GridView2.RowDeleting += .....
      這一行.
      (2)如果需要這個事件,則添加處理該事件的方法,
      方法的具體格式去查MSDN中關于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”)是微軟的默認值,它默認會觸發(fā)RowDeleting事件。

        本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多