2011-03-09 23 views
1

get命令功能是否有PanelCommandName任何容器,CommandArguments而不是使用按鈕(LinkBut​​ton的,ImageButton的,...)?如何從面板

我想在GridView中添加一列來爲行選擇整個單元格的矩形而不是選擇鏈接。

+0

你想實現什麼? – 2011-03-09 12:38:39

+0

@Tim:我編輯了這個問題 – Homam 2011-03-09 14:18:08

回答

1

通過實現IButtonControl接口,可以使(幾乎)任何東西實現CommandNameCommandArguments。您可能還需要實現IPostBackEventHandler界面。

This article確切地涵蓋了您所詢問的內容,通常是:將Panel轉換爲命令控件。這並非完全無關緊要。

但是,使表格行可點擊更容易,但尤其如此。使用jQuery。請參閱this article.您只需將一個事件綁定到該行,然後從該行開始。在此示例中,它們正在重定向到點擊事件中行的鏈接的url。您可以輕鬆地執行其他操作,例如致電__doPostBack以導致異步回傳並運行任意服務器代碼,例如

0

這裏是另一種方式,你如何讓一個GridView,小區排序柱(見RowCreated,其餘爲樣本數據):

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load 
     If Not IsPostBack Then 
      BindGridView() 
     End If 
    End Sub 

    Private Sub BindGridView() 
     Dim source As New List(Of String)(New String() {"1. row", "2. row", "3. row", "4. row", "5. row"}) 
     Me.GridView1.DataSource = source 
     Me.GridView1.DataBind() 
    End Sub 

    Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated 
     Dim cell As New TableCell 
     If e.Row.RowType = DataControlRowType.DataRow Then 
      cell.Text = "select" 
      cell.ToolTip = "click to select row" 
      cell.Attributes("onmouseover") = "this.style.cursor='pointer';" 
      cell.Attributes("onclick") = ClientScript.GetPostBackClientHyperlink(DirectCast(sender, GridView), "Select$" & e.Row.RowIndex) 
     End If 
     e.Row.Cells.Add(cell) 
    End Sub 

編輯:如果你得到一個「無效回發或回調參數「從ASP.Net -Exception,您可以設置EnableEventValidation="False"或添加下列內容頁面的代碼隱藏:

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) 
     For Each row As GridViewRow In GridView1.Rows 
      If row.RowType = DataControlRowType.DataRow Then 
       ClientScript.RegisterForEventValidation(GridView1.UniqueID, "Select$" & row.RowIndex) 
      End If 
     Next 
     MyBase.Render(writer) 
    End Sub 

如果你需要C#,複製全部到:http://www.developerfusion.com/tools/convert/vb-to-csharp/