Re: Get DataKey on RowDataBound

Tech-Archive recommends: Fix windows errors by optimizing your registry



I can get the DataKey using the RowCommand Event but I want to be able
to put the OnClick attribute into the Row and have it alert the KeyID.
When I try to get the value of KeyID that I got in RowCommand it comes
back with a null value. The only way I can find to add an attribute to
a row is during the RowDataBound Event.

Public Class _MasterTestBed
Inherits System.Web.UI.Page
Dim KeyID As String
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand
KeyID = GridView1.DataKeys(e.CommandArgument).Value.ToString
End Sub

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
e.Row.Attributes.Add("onMouseOver",
"this.style.backgroundColor='lightgrey'")
e.Row.Attributes.Add("onMouseOut",
"this.style.backgroundColor='Transparent'")
e.Row.Attributes.Add("onClick", "alert('" + KeyID + "')'")
End If
End Sub
End Class

.



Relevant Pages

  • Re: Confirm messagebox
    ... I have a gridview with the last column to be a buttonfield. ... the RowCommand event will be fired and the ... Protected Sub GridView1_RowDataBound(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Confirm messagebox
    ... I have a gridview with the last column to be a buttonfield. ... the RowCommand event will be fired and the ... Protected Sub GridView1_RowDataBound(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Which row in GridView_RowCommand??
    ... (ByVal sender As Object, _ ... Protected Sub GridView1_RowCommand _ ... Dim dt As New Data.DataTable ... basic and logical of things like the RowCommand event telling you which ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)