VendorClass.ChangeIncExpTransPick
(1)
DataGridItemEventArgs
(1)
ListItemType.AlternatingItem
(1)
Page.Master.FindControl
(1)
ListItemType
(1)
LvIncExpTrans.DataBind
(1)
LvIncExpTrans.DataKeys
(1)
Convert.ToInt32
(1)

Get GridView RowIndex

Asked By DavidC
12-Mar-10 11:43 AM
How can I get the RowIndex of a GridView when clicking on a checkbox in
read-only mode?  I have done it with the code below in a ListView but I
cannot figure out how to do the same in a GridView.  Thanks.

Sub Check_Clicked(ByVal sender As Object, ByVal e As EventArgs)
' Gets the CheckBox object that fired the event.
Dim chkBox As CheckBox = CType(sender, CheckBox)

' Gets the item that contains the CheckBox object.
Dim item As ListViewDataItem = CType(chkBox.Parent, ListViewDataItem)
Dim intTransID As Int32 =
Convert.ToInt32(lvIncExpTrans.DataKeys(item.DataItemIndex).Value)

If VendorClass.ChangeIncExpTransPick(intTransID, chkBox.Checked) =
False Then
Dim tb As TextBox = Page.Master.FindControl("txtMsg")
' Replace ListView1 with ID of your ListView Control
'tb.Text = "TransID sent = " &
lvIncExpTrans.DataKeys(item.DataItemIndex).Value
tb.Text = "The update to the checkbox failed."
End If
lvIncExpTrans.DataBind()
End Sub

--
David

"DavidC" wrote:it is back to the ItemDataBound.

Mr. Arnold replied to DavidC
12-Mar-10 02:35 PM
it is back to the ItemDataBound.

If that event is wired in the asp:DataGrid, then the bound data for the
*one* row that was selected by the user will be selected, as it rolls through
the rows.

e.Item.ItemIndex  is the row that the user selected.

I suspect that you are going to have to set AutoPostBack="true"  so the event
will fier and comes to the codebehind file method.


protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover", "this.style.cursor='hand'");
e.Item.Attributes.Add("onclick", "javascript:__doPostBack" +
+ "')");
}
}


Or you may have to do something with client OnClick and javascript.

I do have it set as autopostback in the GridView as shown below.

DavidC replied to Mr. Arnold
13-Mar-10 11:16 AM
I do have it set as autopostback in the GridView as shown below.  Could I
just add the DataKey field to the Check_Clicked function and read it from
there?  Thanks.

ItemStyle-BackColor="White" ItemStyle-HorizontalAlign="Center">
Checked='<%# Bind("Reconciled") %>' onclick="fillclearedamt(this);"
AutoPostBack="True" oncheckedchanged="Check_Clicked" />

--
David

DavidC wrote:That's autopostback on the Grid control itself needs to be set to

Mr. Arnold replied to DavidC
13-Mar-10 12:15 PM
That's autopostback on the Grid control itself needs to be set to true.
I do not see how an event of the checkbox has any knowledge of an event
belonging to the Grid. They are two different controls with different
event arguments.

You need the event that happened on the Grid so that you can get
e.item.itemindex. E.item.itemindex is a grid control event. You need to
address a grid event, which should be the Grid_ItemDataBound() event.

You go to the method and do a FindControl("ckReconcile"), and if it
comes back not null on the find, then you have the hit on the row the
control is bound in the grid and capture e.itemitemindex (the row),
which can be saved to a hidden field and used later.
I will give that a try. Thanks.--David"Mr. Arnold" wrote:
DavidC replied to Mr. Arnold
13-Mar-10 02:31 PM
I will give that a try. Thanks.
--
David
"Mr. Arnold" wrote:I am really struggling with this.
DavidC replied to Mr. Arnold
13-Mar-10 03:01 PM
I am really struggling with this.  In my original post I showed how I am
doing this in a ListView and it has been working perfectly.  I am confused as
to why the GridView control cannot do the exact same thing.  The ListView is
inside an UpdatePanel as is the GridView.  The ListView checkbox has
AutoPostback="true" and it runs the event and does exactly what I want and it
gets the datakey value that I need to do my processing.  Please let me know
what is different between the 2 controls that I cannot do the exact same
thing.  Thanks.

David
DavidC wrote:Maybe, it is due to the Listview has item events and the gridview
Mr. Arnold replied to DavidC
13-Mar-10 05:20 PM
Maybe, it is due to the Listview has item events and the gridview has row
events that you can get away with it on a Listview what you did. I do not
know.

I forgot what I was doing when the expert sat down with me doing a
hidden field thing on an item within the ItemTemplete to get some other
information I needed, but I could not get to it by any other means using
a RadListView.

it is in the hidden field example that used the Eval in the link. I do
remember on an HTML <TD onClick> that it called a javascript function.
"Mr. Arnold" wrote:That link had some good examples. Thank you.David
DavidC replied to Mr. Arnold
14-Mar-10 09:10 AM
That link had some good examples. Thank you.

David
Post Question To EggHeadCafe