Asp.net 如何从面板获取命令功能
是否有使用CommandName、CommandArguments而不是使用按钮LinkButton、ImageButton等的面板或任何容器Asp.net 如何从面板获取命令功能,asp.net,Asp.net,是否有使用CommandName、CommandArguments而不是使用按钮LinkButton、ImageButton等的面板或任何容器 我想在GridView中添加一列来选择行,即整个单元格的矩形,而不是选择链接。通过实现IButtonControl接口,几乎可以让任何东西实现CommandName和CommandArguments。您可能还需要实现IPostBackEventHandler接口 通常,详细介绍您要询问的内容:将面板变成命令控件。这不完全是小事 但是,使表行可单击要容易得
我想在GridView中添加一列来选择行,即整个单元格的矩形,而不是选择链接。通过实现IButtonControl接口,几乎可以让任何东西实现CommandName和CommandArguments。您可能还需要实现IPostBackEventHandler接口 通常,详细介绍您要询问的内容:将面板变成命令控件。这不完全是小事
但是,使表行可单击要容易得多,尤其是使用jQuery。请看,您只需将一个事件绑定到行,然后从那里开始。在本例中,他们重定向到单击事件行中链接的url。您也可以轻松地执行其他操作,如调用u doPostBack,以引起异步回发并运行任意服务器代码,例如,通过实现IButonControl接口,您几乎可以让任何东西实现CommandName和CommandArguments。您可能还需要实现IPostBackEventHandler接口 通常,详细介绍您要询问的内容:将面板变成命令控件。这不完全是小事
但是,使表行可单击要容易得多,尤其是使用jQuery。请看,您只需将一个事件绑定到行,然后从那里开始。在本例中,他们重定向到单击事件行中链接的url。您也可以轻松地执行其他操作,如调用uu doPostBack,以引起异步回发并运行任意服务器代码,例如以下是另一种方法,您可以将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获得无效回发或回调参数异常,则可以将EnableEventValidation设置为False,或将以下内容添加到页面的codebehind中:
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,请将所有内容复制到:以下是另一种方法,可以将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获得无效回发或回调参数异常,则可以将EnableEventValidation设置为False,或将以下内容添加到页面的codebehind中:
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,请将所有内容复制到: