Gridview Button Help

bgreer5050

New member
Joined
Jul 4, 2009
Messages
4
Programming Experience
Beginner
I have a gridview with a command button. I would like to response.write the column named EmployeeID of the row where the button was clicked. How do I do this? My code and code behind is below: :D



01.<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="vacationmanagement.aspx.vb" Inherits="Admin_vacationmanagement" title="Untitled Page" %>
02.
03.<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
04.
05.
06.
07.</asp:Content>
08.
09.<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
10. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
11. DataKeyNames="ClockNo" DataSourceID="SqlDataSource1">
12. <Columns>
13. <asp:BoundField DataField="ClockNo" HeaderText="ClockNo" ReadOnly="True"
14. SortExpression="ClockNo" />
15. <asp:BoundField DataField="FirstName" HeaderText="FirstName"
16. SortExpression="FirstName" />
17. <asp:BoundField DataField="LastName" HeaderText="LastName"
18. SortExpression="LastName" />
19. <asp:BoundField DataField="Password" HeaderText="Password"
20. SortExpression="Password" />
21. <asp:BoundField DataField="StartDate" HeaderText="StartDate"
22. SortExpression="StartDate" />
23. <asp:BoundField DataField="Active" HeaderText="Active"
24. SortExpression="Active" />
25. <asp:BoundField DataField="VacationDaysRemaining"
26. HeaderText="VacationDaysRemaining" SortExpression="VacationDaysRemaining" />
27. <asp:BoundField DataField="VacationGroupId" HeaderText="VacationGroupId"
28. SortExpression="VacationGroupId" />
29. <asp:BoundField DataField="Shift" HeaderText="Shift" SortExpression="Shift" />
30. <asp:BoundField DataField="SenirorityNumber" HeaderText="SenirorityNumber"
31. SortExpression="SenirorityNumber" />
32. <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
33. <asp:ButtonField CommandName="Test" Text="Button" />
34. </Columns>
35. </asp:GridView>
36. <asp:SqlDataSource ID="SqlDataSource1" runat="server"
37. ConnectionString="<%$ ConnectionStrings:VACATIONSConnectionString %>"
38. SelectCommand="SELECT * FROM [EMPLOYEE]"></asp:SqlDataSource>
39.</asp:Content>
40.
41.
42.
43.
44.
45.
46.
47.
48.Partial Class Admin_vacationmanagement
49. Inherits System.Web.UI.Page
50.
51.
52. Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
53.
54. If e.CommandName = "Test" Then
55.
56. Dim strWrite As String
57. Dim index As Integer = Convert.ToInt32(e.CommandArgument)
58.
59. strWrite = (index.ToString)
60.
61. Response.Write(strWrite)
62. ' Response.Write(GridView1.SelectedRow.FindControl("EmployeeID").ToString)
63.
64. End If
65.
66.
67. End Sub
68.End Class
 

Latest posts

Back
Top