what..which..who? An in-built click event of the Gridview? Explain..
Main Topics
Browse All TopicsHi experts,
I have a vb.net page with a gridview on it.
I have successfully set it up so when the mouse hovers over a row, the background row color changes. But now, I want to be able to click on the row and call a subroutine in the code behind page.
So essentially, I have a sub procedure in my code behind code called SelectedRow(ByVal QueryId as Integer)
So I want to set up the OnClick event (I'm using ASP.NET v2.0 by the way) so that when the user clicks on the row, it calls the SelectedRow sub procedure.
Here is my code so far:
Protected Sub GridView1_RowCreated(ByVal
If e.Row.RowType = DataControlRowType.DataRow
Dim dv As DataRowView = CType(e.Row.DataItem, DataRowView)
Dim str As String = "javascript:__doPostBack('
e.Row.Attributes.Add("onmo
e.Row.Attributes.Add("onmo
'Dim strUrl As String = CStr(GridView1.DataKeys(e.
Dim strUrl As String = CStr(GridView1.DataKeys(e.
'e.Row.Attributes.Add("OnC
e.Row.Attributes.Add("OnCl
End If
End Sub
I really don't want to use javascript but I suppose I will if I must.
Thanks! This is super duper urgent!
rss2
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here's my grid view definition:
<asp:GridView ID="LeaveRequests" runat="server" AutoGenerateColumns="False
DataSourceID="LeaveRequest
<Columns>
<asp:BoundField DataField="start_date" HeaderText="Start" HtmlEncode="False" SortExpression="start_date
<ItemStyle CssClass="item" />
<HeaderStyle CssClass="header" />
</asp:BoundField>
<asp:BoundField DataField="start_part" SortExpression="start_part
<ItemStyle CssClass="item" />
<HeaderStyle CssClass="header" />
</asp:BoundField>
<asp:BoundField DataField="end_date" HeaderText="End" HtmlEncode="False" SortExpression="end_date" DataFormatString="{0:d}">
<ItemStyle CssClass="item" />
<HeaderStyle CssClass="header" />
</asp:BoundField>
<asp:BoundField DataField="end_part" SortExpression="end_part">
<ItemStyle CssClass="item" />
<HeaderStyle CssClass="header" />
</asp:BoundField>
<asp:BoundField DataField="duration" HeaderText="Duration" HtmlEncode="False" SortExpression="duration" DataFormatString="{0:##0.#
<ItemStyle CssClass="itemr" />
<HeaderStyle CssClass="header" />
</asp:BoundField>
<asp:BoundField DataField="type_name" HeaderText="Type" SortExpression="type_name"
<ItemStyle CssClass="item" />
<HeaderStyle CssClass="header" />
</asp:BoundField>
<asp:BoundField DataField="status_name" HeaderText="Status" SortExpression="status_nam
<HeaderStyle CssClass="header" />
<ItemStyle CssClass="itemapproved" />
</asp:BoundField>
<asp:ButtonField CommandName="CANCEL" Text="Cancel">
<HeaderStyle CssClass="header" />
<ItemStyle CssClass="item" />
</asp:ButtonField>
</Columns>
<SelectedRowStyle CssClass="selected" />
</asp:GridView>
Note the asp:ButtonField
This is the corresponding event that is fired when you click the button in the grid (note I check the CommandName to make sure I am handling the correct command as multiple buttons in the grid will fire this one event so you have to check which button type was clicked):
Protected Sub LeaveRequests_RowCommand(B
If e.CommandName = CANCEL_COMMAND Then
Dim requestId As Integer = CType(LeaveRequests.DataKe
p.RequestCancellation(requ
"")
LoadCurrentLeaveEntitlemen
End If
End Sub
Business Accounts
Answer for Membership
by: culshajaPosted on 2007-06-25 at 07:45:53ID: 19356024
Why not just use the inbuilt click event of the GridView? Granted you need to use a linkbutton control to cause the postback but its very simple to do.
James :-)