|
-
Apr 19th, 2005, 02:06 AM
#1
Thread Starter
Fanatic Member
-
Apr 19th, 2005, 09:23 AM
#2
Addicted Member
Re: handle fire event when row clicked in a datagrid
Rather than using item templates, use a buttoncolumn like this:
Code:
<asp:ButtonColumn ButtonType="LinkButton" Text="Edit" CommandName="Select"></asp:ButtonColumn>
When the user clicks on this you need to get the client that they clicked on. So what you need to do is to put this code in your <asp:datagrid> tag
Code:
OnItemCommand="viewRow" DataKeyField="CLIE_CODE"
You must then define this 'viewRow' event in your page behind. Something like this...
VB Code:
Public Sub viewRow(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
If Not e.Item.ItemIndex = -1 Then
'put code here
Dim ID as String = ctype(dgrGrid.DataKeys(e.Item.ItemIndex), string)
'etc....
End If
End Sub
dgrGrid.DataKeys(e.Item.ItemIndex) gives you the keyfield (CLIE_CODE) for the selected row that you specified in your <asp:datagrid> tag
I think thats about right
-
Apr 21st, 2005, 07:20 AM
#3
I wonder how many charact
Re: handle fire event when row clicked in a datagrid
Architecturally, you wouldn't want the server to have to post-back the form to take you to another page. The ID of the row (record what have you), should be in the link to the other page.
Your goal would be to have the html output look like this...
<a href="ItemEdit.aspx?id=123">Edit</a>
An anchor link will make the client Get a request for ItemEdit.aspx with the id parameter filled in.
A linkbutton has to post-back to the page that rendered the current response, wire everything up, then ascertain that the user clicked a button, fire your event handler, which would then initiate a response.redirect to ItemEdit.aspx. In a high-volume site, that would be just simple overkill.
As you can easily see, the former method is much faster.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|