Hyperlinkcolumn, or buttoncolumn to post data

N

Not Me

Hi,

Very new to this, so apologies if I go completely wrong :)
I'm wanting to create a link to a separate page based on data in a
datagrid. I can get it working almost how I want it using a
hyperlinkcolumn. The problem with this, is that the data I wish to pass
to the next page is visible in the link (like a get request). I wish to
'post' this information, so it's less visible to the user. Do I need to
use a button for this behaviour? If so, how do I go about posting
information to a seperate page?

Thanks for any pointers you can give,
Chris
 
J

Joe Fallon

1. Use a Button or image button. Set the CommandName property the same as
the ID property for convenience.
2. In the grid properties you set the OnItemCommand="SomeMethod"
3. In your code behind you define Sub "SomeMethod"
4. Inside this method you figure out which button got clicked by using:
If e.CommandName="myButtonCommandName"
5. Cast the sender to datagrid and then figure out which row index was
clicked.(Take paging into account.)
Dim mIndex As Integer = CType(source, DataGrid).PageSize * CType(source,
DataGrid).CurrentPageIndex + e.Item.ItemIndex

Something like this:

Protected Sub GetRowInfo(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)
'Grid paging causes this event to fire (among others) and
e.Item.ItemIndex=-1 so we should avoid an error by coding for this case.
If e.Item.ItemIndex >= 0 Then

If e.CommandName="myButtonCommandName" Then
Dim mIndex As Integer = CType(source, DataGrid).PageSize *
CType(source, DataGrid).CurrentPageIndex + e.Item.ItemIndex

'get your collection object out of session:
mList = Session("myList")

'us mIndex to find the row in your collection and then pull out
the property you are looking for.
mSomeInt=mList(mIndex).someint

'do something with the property
Response.Redirect("SomeOtherPage.aspx?value=" & mSomeInt)
End If

End If
End Sub
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top