ki_ki
asked on
How to find Button in GridView edit template
Hi all,
I have gridview1 with template columns.
In one of the columns I have gridView2 with template columns too. In the edittemplate, gridview2, I have a button (insertDateCodeButton) and I want to set the commandArgument of that button to e.Row.RowIndex. How do I "find" insertdateCodeButton?
I am using:
Protected Sub GridView2_RowDataBound(ByV al sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs )
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowState = DataControlRowState.Edit Then
CType(e.Row.FindControl("a ddNewDateC odeButton" ), Button).CommandArgument = e.Row.RowIndex
End If
End If
End Sub
The if statement is true for only row number:0,2,4 , etc... How do i get the alternate rows?
Thank you !
I have gridview1 with template columns.
In one of the columns I have gridView2 with template columns too. In the edittemplate, gridview2, I have a button (insertDateCodeButton) and I want to set the commandArgument of that button to e.Row.RowIndex. How do I "find" insertdateCodeButton?
I am using:
Protected Sub GridView2_RowDataBound(ByV
If e.Row.RowType = DataControlRowType.DataRow
If e.Row.RowState = DataControlRowState.Edit Then
CType(e.Row.FindControl("a
End If
End If
End Sub
The if statement is true for only row number:0,2,4 , etc... How do i get the alternate rows?
Thank you !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it's not the same, look at the code
(e.Row.RowState & DataControlRowState.Edit) > 0
is a bitwise compare
the problem is on alternate rows, the row state is actually a combination of edit and alternate row states, so what the above statement does is looks at the bit mask for just the edit portion to see if it is set
(e.Row.RowState & DataControlRowState.Edit) > 0
is a bitwise compare
the problem is on alternate rows, the row state is actually a combination of edit and alternate row states, so what the above statement does is looks at the bit mask for just the edit portion to see if it is set
ASKER
I converted your c# code wrongly to vb.net.
But now it works:
If e.Row.RowType = DataControlRowType.DataRow And (e.Row.RowState And DataControlRowState.Edit) > 0 Then
CType(e.Row.FindControl("a ddNewDateC odeButton" ), Button).CommandArgument = e.Row.RowIndex
End If
Thank you!!!!!!
But now it works:
If e.Row.RowType = DataControlRowType.DataRow
CType(e.Row.FindControl("a
End If
Thank you!!!!!!
ASKER
Thank you!
Here's the VB.NET Version
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) And ((e.Row.RowState And DataControlRowState.Edit) > 0)) Then
Dim btn As Button = e.Row.FindControl("insertDateCodeButton")
btn.CommandArgument = e.Row.RowIndex.ToString()
btn.Text = e.Row.RowIndex.ToString()
End If
End Sub
Cool glad you got it working :)
ASKER
"e.Row.RowType == DataControlRowType.DataRow
" If e.Row.RowType = DataControlRowType.DataRow
If e.Row.RowState = DataControlRowState.Edit Then "
Am I missing something?