2012-08-01 39 views
-1

我在按鈕的onclick事件有一個功能:函數調用中的問題?

protected void show() 
    { 
     try 
     { 

      SqlConnection con = new SqlConnection(getconnectionstring()); 
      con.Open(); 
      DataTable dt = new DataTable(); 
      SqlCommand cmd = new SqlCommand(); 
      cmd.CommandText = "paging_select"; 
      cmd.Connection = con; 

      cmd.CommandType = CommandType.StoredProcedure; 
      cmd.Parameters.AddWithValue("@startrowindex", current_page_number); 
      cmd.Parameters.AddWithValue("@maximumrows", page_size); 
      cmd.Parameters.Add("@totalrows", SqlDbType.Int, 4); 
      cmd.Parameters["@totalrows"].Direction = 
          ParameterDirection.Output; 
      SqlDataAdapter sda = new SqlDataAdapter(cmd); 



      sda.Fill(dt); 
      int totalRows = (int)cmd.Parameters["@totalrows"].Value; 
      sda.Dispose(); 
      gridview.DataSource = dt; 
      gridview.DataBind(); 
      con.Close(); 
      // Response.Write("Total rows=" + totalRows + "<br/>"); 


      //Response.Write("total pages will be" + totalpages_counter(totalRows).ToString() + "having 3 records per page" + "<br/>"); 
      label2.Text = current_page_number.ToString(); 
      // label2.Visible = false; 
      label3.Text = totalpages_counter(totalRows).ToString(); 
      // label3.Visible = false; 
      // Response.Write("Page" + " " + label2.Text + " " + "of" + " " + label3.Text); 

     } 
     catch (Exception ee) 
     { 
      Response.Write(ee.Message); 
     } 

    } 

執行它給人一種錯誤。

錯誤1,沒有超載的「秀」匹配委託「System.EventHandler」

我希望它的,因爲功能沒有argument.But我的問題是,我想在一個函數來執行該代碼其中可能沒有任何參數,例如受保護的returntype funtionname()。它應該是這樣的,因爲我必須從別的地方調用這個函數。 或更好的,你能告訴我如何調用一個函數,它是以下類型:

private void Button1_Click(object sender, EventArgs e) 
{ 
    show(); 
} 
+0

請問您可以將標記C更改爲C#以避免造成混淆? – 2012-08-01 12:16:12

+0

您可以刪除所有的Db代碼,這是不相關的。並且請更好地描述你想如何使用它。用代碼。 – 2012-08-01 12:22:09

回答

1

剛剛從一個點擊處理程序與正確的簽名打電話給你的方法爲動態創建的控件提供了一種替代方案(或者只是通過代碼而非設計器綁定的事件)。

myButton.Click += new EventHandler((sender, e) => show()); 

那倒設置簡單的事件處理程序,那麼這將只是調用您show()方法。

0

再增加一個答案:

protected void show(Object sender,EventArgs e)