By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,719 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

datagrid_ItemCommand problem

P: n/a
Hi there

I am using a button column>SELECT and a datagrid.Item_Command to take a
value from the datagrid (in this case a customer account number) - store that
value in to a session variable and transfer to another page which picks up
the session variable and uses it to display information for that particular
customer:

Public Sub CustomerSearchGrid_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
CustomerSearchGrid.ItemCommand
If e.Item.ItemIndex >= 0 Then

Dim Ownercell1 As TableCell = CType(e.Item.Controls(1), TableCell)

UserSession.Current.CurrentAccNumber = Ownercell1.Text & "%"
Server.Transfer("/webapplication/CustomerBasicInfo.aspx")
End If
End Sub

This works great on the first click. However, if I then click on BACK and
choose another customer by clicking SELECT on the datagrid the above event
does not fire - anyone know what I am doing wrong please ???

Thanks very much for your help
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I know this sounds strange...but humor me....
Change your button to a Link Button and see if that fixes it
"Stuart" <St****@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
Hi there

I am using a button column>SELECT and a datagrid.Item_Command to take a
value from the datagrid (in this case a customer account number) - store that value in to a session variable and transfer to another page which picks up
the session variable and uses it to display information for that particular customer:

Public Sub CustomerSearchGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
CustomerSearchGrid.ItemCommand
If e.Item.ItemIndex >= 0 Then

Dim Ownercell1 As TableCell = CType(e.Item.Controls(1), TableCell)
UserSession.Current.CurrentAccNumber = Ownercell1.Text & "%"
Server.Transfer("/webapplication/CustomerBasicInfo.aspx")
End If
End Sub

This works great on the first click. However, if I then click on BACK and
choose another customer by clicking SELECT on the datagrid the above event
does not fire - anyone know what I am doing wrong please ???

Thanks very much for your help

Nov 19 '05 #2

P: n/a
Hi David (by the way this relates to the session variables HELP!! problem
that you have already helped me with....)

Do you mean a hyperlink ? If so - how do I store the session variable ?
(recognise the code ;-) )

If you mean a SELECT column with button type: set to linkbutton - it already
is I'm afraid... in fact if I change it to pushbutton the event doesn't seem
to fire in the first place...

I have been messing around with using _SelectedIndexChanged instead as I am
starting to assume that when you click BACK to a page with a grid from a page
that is linked by the _ItemCommand event from that same grid originally, for
whatever reason, _ItemCommand simply doesn't want to play.... However, I
can't work out how to get the value from the datagrid in to Session when
using this event as Ctype(e.item.controls(1), TableCell) is thoroughly not
availale in the same way as under _ItemCommand event - perhaps you have some
thoughts on this ???

I reason that _SelectedIndexChanged may be more accessible in my particular
environment ? (there is much scope for me being wrong on this subject I'm
afraid - so please ignore and supply any other ideas you may have if that is
obvious....)

Thanks for all your help David

"David Jessee" wrote:
I know this sounds strange...but humor me....
Change your button to a Link Button and see if that fixes it
"Stuart" <St****@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
Hi there

I am using a button column>SELECT and a datagrid.Item_Command to take a
value from the datagrid (in this case a customer account number) - store

that
value in to a session variable and transfer to another page which picks up
the session variable and uses it to display information for that

particular
customer:

Public Sub CustomerSearchGrid_ItemCommand(ByVal source As Object, ByVal e

As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
CustomerSearchGrid.ItemCommand
If e.Item.ItemIndex >= 0 Then

Dim Ownercell1 As TableCell = CType(e.Item.Controls(1),

TableCell)

UserSession.Current.CurrentAccNumber = Ownercell1.Text & "%"
Server.Transfer("/webapplication/CustomerBasicInfo.aspx")
End If
End Sub

This works great on the first click. However, if I then click on BACK and
choose another customer by clicking SELECT on the datagrid the above event
does not fire - anyone know what I am doing wrong please ???

Thanks very much for your help


Nov 19 '05 #3

P: n/a
Well, as far as getting a value from a cell, let's say that the field you're
looking for is called "IdField". Set your datagrid's DataKeyField to
"IdField" that way when you're inside of the handler, refer to
MyGrid.DataKeys(e.Item.Itemindex).

as far as SelectedIndexChanged.....

SelectedIndexChanged, SelectCommand, DeleteCommand, UpdateCommand and all of
the rest of those "command" events are just overloads of the ItemCommand
Event. Feel Free to do what you need to, but I only ude the ItemCommand
because that way I don't end up with 20 event handlers.
"Stuart" <St****@discussions.microsoft.com> wrote in message
news:18**********************************@microsof t.com...
Hi David (by the way this relates to the session variables HELP!! problem
that you have already helped me with....)

Do you mean a hyperlink ? If so - how do I store the session variable ?
(recognise the code ;-) )

If you mean a SELECT column with button type: set to linkbutton - it already is I'm afraid... in fact if I change it to pushbutton the event doesn't seem to fire in the first place...

I have been messing around with using _SelectedIndexChanged instead as I am starting to assume that when you click BACK to a page with a grid from a page that is linked by the _ItemCommand event from that same grid originally, for whatever reason, _ItemCommand simply doesn't want to play.... However, I
can't work out how to get the value from the datagrid in to Session when
using this event as Ctype(e.item.controls(1), TableCell) is thoroughly not
availale in the same way as under _ItemCommand event - perhaps you have some thoughts on this ???

I reason that _SelectedIndexChanged may be more accessible in my particular environment ? (there is much scope for me being wrong on this subject I'm
afraid - so please ignore and supply any other ideas you may have if that is obvious....)

Thanks for all your help David

"David Jessee" wrote:
I know this sounds strange...but humor me....
Change your button to a Link Button and see if that fixes it
"Stuart" <St****@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
Hi there

I am using a button column>SELECT and a datagrid.Item_Command to take a value from the datagrid (in this case a customer account number) - store
that
value in to a session variable and transfer to another page which
picks up the session variable and uses it to display information for that

particular
customer:

Public Sub CustomerSearchGrid_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
CustomerSearchGrid.ItemCommand
If e.Item.ItemIndex >= 0 Then

Dim Ownercell1 As TableCell = CType(e.Item.Controls(1),

TableCell)

UserSession.Current.CurrentAccNumber = Ownercell1.Text &

"%" Server.Transfer("/webapplication/CustomerBasicInfo.aspx")
End If
End Sub

This works great on the first click. However, if I then click on BACK and choose another customer by clicking SELECT on the datagrid the above event does not fire - anyone know what I am doing wrong please ???

Thanks very much for your help


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.