datagrid_ItemCommand problem

G

Guest

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
 
D

David Jessee

I know this sounds strange...but humor me....
Change your button to a Link Button and see if that fixes it
 
G

Guest

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
 
D

David Jessee

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top