Hello,
I have been looking at this problem for a couple of days with no luck. I had a selectable gridview in an ordinary web form that was working, but when I converted my solution to use a master page, this one with the selectable gridview stopped working. By stopped working, I mean, when I select a row in the GridView, a postback occurs, but the row isn't selected. Other controls on the form work, such as the command buttons and login control. There are two gridviews on the page, each bound to its own accessdatasource, whose select statements are dynamically generated in the page_load event. Please help!
CONTENT PAGE:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" EnableEventValidation="false" AutoEventWireup="true" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' The first year of use of this application, I noticed a lot of
' people were logging out, and then using the back button of
' their browser to complete forms. So, data was being submitted
' without a login ID. This part prevents that.
If (Session("ID") Is Nothing) Then
Session.Clear()
Response.Redirect("../Default.aspx")
End If
' Dynamically set the access-data-source database, based on the year.
adsStaffProfiles.DataFile = "F:\Databases\McNair\" & Session("year") & " mcnair conference.mdb"
adsStudentProfiles.DataFile = "F:\Databases\McNair\" & Session("year") & " mcnair conference.mdb"
' This happens after this group has completed the payment page.
If Session("payment_info") = "Yes" Then
lblPayment.Text = "<h3>(Complete)</h3>"
lblPayment.ForeColor = Drawing.Color.Green
End If
' Use this to count the staff in the group, whether they have
' cancelled or not.
adsStaffProfiles.SelectCommand = _
"SELECT * FROM staff WHERE ID='" & Session("ID") & "'"
grdStaff.DataSourceID = "adsStaffProfiles"
' Use this to count the students in the group, whether they have
' cancelled or not.
adsStudentProfiles.SelectCommand = _
"SELECT * FROM student WHERE ID='" & Session("ID") & "'"
grdStudents.DataSourceID = "adsStudentProfiles"
' We will use this session value in case a new member needs to
' be inserted. The member's MemberKey will be set to this.
Session("group_members") = CType(grdStaff.Rows.Count + grdStudents.Rows.Count, String)
' Get only the non-cancelled staff.
adsStaffProfiles.SelectCommand = _
"SELECT * FROM staff WHERE ID='" & Session("ID") & "' AND cancel='No';"
grdStaff.DataBind()
' Get only the non-cancelled students.
adsStudentProfiles.SelectCommand = _
"SELECT * FROM student WHERE ID='" & Session("ID") & "' AND cancel='No';"
grdStudents.DataBind()
' Display the right options, depending on whether the group size
' limit has been reached.
If grdStaff.Rows.Count + grdStudents.Rows.Count < CType(Session("group_size"), Integer) Or _
Session("Exception") = "True" Then
btnAddStaff.Enabled = True
btnAddStudent.Enabled = True
lblAddStaff.Text = ""
lblAddStudent.Text = ""
Else
btnAddStaff.Enabled = False
btnAddStudent.Enabled = False
lblAddStaff.Text = "(Group size limit is " & Session("group_size") & ")"
lblAddStudent.Text = "(Group size limit is " & Session("group_size") & ")"
End If
' Retrieve the number of oral and poster presenters from the
' database.
If Session("Exception") = "False" Then
Session("Orals") = CType(Orals(), String)
Session("Posters") = CType(Posters(), String)
End If
End Sub
' This sub set the correct options for the staff depending on which
' row of the gridview is selected.
Protected Sub staff_changed(ByVal sender As Object, ByVal e As System.EventArgs)
If grdStaff.SelectedIndex >= 0 Then
btnUpdateStaff.Enabled = True
Else
btnUpdateStaff.Enabled = False
End If
If staff_done(grdStaff.SelectedIndex()) Then
btnRemoveStaff.Enabled = True
lblRemoveStaff.Visible = False
ElseIf grdStaff.SelectedIndex < 0 Then
lblRemoveStaff.Visible = False
Else
btnRemoveStaff.Enabled = False
lblRemoveStaff.Visible = True
End If
End Sub
' This sub set the correct options for the student depending on which
' row of the gridview is selected.
Protected Sub student_changed(ByVal sender As Object, ByVal e As System.EventArgs)
If grdStudents.SelectedIndex >= 0 Then
btnUpdateStudent.Enabled = True
Else
btnUpdateStudent.Enabled = False
End If
If student_done(grdStudents.SelectedIndex()) Then
btnRemoveStudent.Enabled = True
lblRemoveStudent.Visible = False
ElseIf grdStudents.SelectedIndex < 0 Then
lblRemoveStudent.Visible = False
Else
btnRemoveStudent.Enabled = False
lblRemoveStudent.Visible = True
End If
End Sub
' Used on logout.
Protected Sub AbandonSession(ByVal sender As Object, ByVal e As System.EventArgs)
Session.Abandon()
End Sub
' Retrieves the number of poster presenters from the database.
Protected Function Posters() As Integer
Dim i As Integer
Dim sum As Integer
For i = 0 To grdStudents.Rows.Count - 1
If grdStudents.Rows(i).Cells(25).Text = "Poster" Then
sum = sum + 1
End If
Next
Posters = sum
End Function
' Retrieves the number of oral presenters from the database.
Protected Function Orals() As Integer
Dim i As Integer
Dim sum As Integer
For i = 0 To grdStudents.Rows.Count - 1
If grdStudents.Rows(i).Cells(25).Text = "Oral" Then
sum = sum + 1
End If
Next
Orals = sum
End Function
' This function is used to determine if a staff member has completed
' both the contact and lodging forms.
Protected Function staff_done(ByVal i As Integer) As Boolean
If (i < 0) Then
staff_done = False
Exit Function
End If
Dim datStaff As System.Data.DataRowView
datStaff = CType(adsStaffProfiles.Select(DataSourceSelectArguments.Empty), System.Data.DataView).Item(i)
If (datStaff.Item(35).ToString = "Done" And _
datStaff.Item(36).ToString = "Done") Then
staff_done = True
Else
staff_done = False
End If
End Function
' This function is used to determine if a student member has completed
' both the contact and lodging forms.
Protected Function student_done(ByVal i As Integer) As Boolean
If (i < 0) Then
student_done = False
Exit Function
End If
Dim datStudent As System.Data.DataRowView
datStudent = CType(adsStudentProfiles.Select(DataSourceSelectArguments.Empty), System.Data.DataView).Item(i)
If (datStudent.Item(45).ToString = "Done" And _
datStudent.Item(47).ToString = "Done") Then
student_done = True
Else
student_done = False
End If
End Function
' This sub makes sure each row has the appropriate fields displayed
' for a person. We only want the most important ones displayed, since
' there are so many. It also put a select cell at the end of each
' row and a label stating whether the member for the row has completed
' the required forms.
Protected Sub format_row(ByVal sender As Object, _
ByVal e As GridViewRowEventArgs)
Dim SelectCell As New TableCell
Dim LabelCell As New TableCell
If CType(sender, GridView).ID = "grdStaff" Then
SelectCell.Text = "<a href=javascript:__doPostBack('grdStaff','Select$" & _
e.Row.RowIndex & "') class='UpdateLink'>Select</a>"
If e.Row.Cells(35).Text = "Done" And e.Row.Cells(36).Text = "Done" Then
LabelCell.Text = "(Complete)"
Else
LabelCell.Text = "(Incomplete)"
End If
Else
SelectCell.Text = "<a href=javascript:__doPostBack('grdStudents','Select$" & _
e.Row.RowIndex & "') class='UpdateLink'>Select</a>"
If e.Row.Cells(45).Text = "Done" And e.Row.Cells(47).Text = "Done" Then
LabelCell.Text = "(Complete)"
Else
LabelCell.Text = "(Incomplete)"
End If
End If
e.Row.Cells(0).Visible = False
e.Row.Cells(1).Visible = False
If e.Row.Cells(2).Text = " " Then
e.Row.Cells(2).Text = "(blank)"
e.Row.Cells(3).Text = "(blank)"
e.Row.Cells(4).Text = "(blank)"
e.Row.Cells(5).Text = "(blank)"
e.Row.Cells(6).Text = "(blank)"
End If
Dim k As Integer
For k = 7 To e.Row.Cells.Count - 1
e.Row.Cells(k).Visible = False
Next
e.Row.Cells.Add(SelectCell)
e.Row.Cells.Add(LabelCell)
End Sub
' Executed when the update staff button is clicked. Loads the staff
' member's data and goes to the next page.
Protected Sub UpdateStaff(ByVal sender As Object, ByVal e As System.EventArgs)
CreateStaffSession(grdStaff.SelectedIndex)
Response.Redirect("Staff/Default.aspx")
End Sub
' Executed when the remove staff button is clicked. We first load the
' appropriate values and then navigate to the cancel page.
Protected Sub RemoveStaff(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Key") = grdStaff.Rows(grdStaff.SelectedIndex).Cells(1).Text
Session("txtFirstName") = grdStaff.Rows(grdStaff.SelectedIndex).Cells(2).Text
Session("txtLastName") = grdStaff.Rows(grdStaff.SelectedIndex).Cells(4).Text
Session("Amount") = grdStaff.Rows(grdStaff.SelectedIndex).Cells(28).Text
Session("StaffORStudent") = "Staff"
Response.Redirect("Cancel.aspx")
End Sub
' Executed when the update student button is clicked. Loads the student
' member's data and goes to the next page.
Protected Sub UpdateStudent(ByVal sender As Object, ByVal e As System.EventArgs)
CreateStudentSession(grdStudents.SelectedIndex)
Response.Redirect("Student/Default.aspx")
End Sub
' Executed when the remove student button is clicked. We first load the
' appropriate values and then navigate to the cancel page.
Protected Sub RemoveStudent(ByVal sender As Object, ByVal e As System.EventArgs)
Session("Key") = grdStudents.Rows(grdStudents.SelectedIndex).Cells(1).Text
Session("txtFirstName") = grdStudents.Rows(grdStudents.SelectedIndex).Cells(2).Text
Session("txtLastName") = grdStudents.Rows(grdStudents.SelectedIndex).Cells(4).Text
Session("Amount") = grdStudents.Rows(grdStudents.SelectedIndex).Cells(38).Text
Session("StaffORStudent") = "Student"
Response.Redirect("Cancel.aspx")
End Sub
' Used when we need to update a staff member. Loads all of the
' staff member's data into the appropriate session variables.
Protected Sub CreateStaffSession(ByVal i As Integer)
Dim datStaff As System.Data.DataRowView
datStaff = CType(adsStaffProfiles.Select(DataSourceSelectArguments.Empty), System.Data.DataView).Item(i)
Session("Key") = datStaff.Item(1).ToString
Session("AtCapacity") = datStaff.Item(34).ToString
Session("contact_info") = datStaff.Item(35).ToString
Session("lodging_plans") = datStaff.Item(36).ToString
If Session("contact_info") = "Done" Then
Session("txtAddress") = datStaff.Item(21).ToString
Session("txtCity") = datStaff.Item(22).ToString
Session("ddlStates") = datStaff.Item(23).ToString
Session("txtZip") = datStaff.Item(24).ToString
Session("txtAreaCode") = Mid(datStaff.Item(25).ToString, 2, 3)
Session("txtPhone1") = Mid(datStaff.Item(25).ToString, 7, 3)
Session("txtPhone2") = Right(datStaff.Item(25).ToString, 4)
Session("txtFaxArea") = Mid(datStaff.Item(26).ToString, 2, 3)
Session("txtFax1") = Mid(datStaff.Item(26).ToString, 7, 3)
Session("txtFax2") = Right(datStaff.Item(26).ToString, 4)
Session("txtEmail") = datStaff.Item(27).ToString
End If
If Session("lodging_plans") = "Done" Then
Session("txtFirstName") = datStaff.Item(2).ToString
Session("txtMiddleName") = datStaff.Item(3).ToString
Session("txtLastName") = datStaff.Item(4).ToString
Session("txtTitle") = datStaff.Item(5).ToString
Session("txtInstitution") = datStaff.Item(6).ToString
Session("rblModerator") = datStaff.Item(7).ToString
Session("rblRoom") = datStaff.Item(8).ToString
Session("rblExhibitor") = datStaff.Item(9).ToString
If (Session("rblExhibitor") = "Yes") Then
Session("txtCollege") = datStaff.Item(10).ToString
Session("txtDescription") = datStaff.Item(11).ToString
End If
Session("txtRoommate1First") = datStaff.Item(12).ToString
Session("txtRoommate1Middle") = datStaff.Item(13).ToString
Session("txtRoommate1Last") = datStaff.Item(14).ToString
Session("txtRoommate2First") = datStaff.Item(15).ToString
Session("txtRoommate2Middle") = datStaff.Item(16).ToString
Session("txtRoommate2Last") = datStaff.Item(17).ToString
Session("txtRoommate3First") = datStaff.Item(18).ToString
Session("txtRoommate3Middle") = datStaff.Item(19).ToString
Session("txtRoommate3Last") = datStaff.Item(20).ToString
Session("Amount") = datStaff.Item(28).ToString
Response.Write(Session("Amount"))
End If
Session("date_submitted") = datStaff.Item(29).ToString
Session("Update") = "True"
End Sub
' Used when we need to update a student member. Loads all of the
' student member's data into the appropriate session variables.
Protected Sub CreateStudentSession(ByVal i As Integer)
Dim datStudent As System.Data.DataRowView
datStudent = CType(adsStudentProfiles.Select(DataSourceSelectArguments.Empty), System.Data.DataView).Item(i)
Session("Key") = datStudent.Item(1).ToString
Session("AtCapacity") = datStudent.Item(44).ToString
Session("contact_info") = datStudent.Item(45).ToString
Session("presenter") = datStudent.Item(46).ToString
Session("lodging_plans") = datStudent.Item(47).ToString
If Session("contact_info") = "Done" Then
Session("txtAddress") = datStudent.Item(18).ToString
Session("txtCity") = datStudent.Item(19).ToString
Session("ddlStates") = datStudent.Item(20).ToString
Session("txtZip") = datStudent.Item(21).ToString
Session("txtAreaCode") = Mid(datStudent.Item(22).ToString, 2, 3)
Session("txtPhone1") = Mid(datStudent.Item(22).ToString, 7, 3)
Session("txtPhone2") = Right(datStudent.Item(22).ToString, 4)
Session("txtEmail") = datStudent.Item(23).ToString
Session("txtMajor") = datStudent.Item(24).ToString
End If
If Session("presenter") = "Done" Then
Session("rblPresType") = datStudent.Item(25).ToString
Session("txtTitle") = datStudent.Item(26).ToString
Session("txtResDept") = datStudent.Item(27).ToString
Session("txtAbstract") = datStudent.Item(28).ToString
Session("txtMentorFirst") = datStudent.Item(29).ToString
Session("txtMentorMiddle") = datStudent.Item(30).ToString
Session("txtMentorLast") = datStudent.Item(31).ToString
Session("txtMentDisc") = datStudent.Item(32).ToString
Session("txtMentInst") = datStudent.Item(33).ToString
Session("chkEquipment1") = datStudent.Item(34).ToString
Session("chkEquipment2") = datStudent.Item(35).ToString
Session("chkEquipment3") = datStudent.Item(36).ToString
Session("chkEquipment4") = datStudent.Item(37).ToString
End If
If Session("lodging_plans") = "Done" Then
Session("txtFirstName") = datStudent.Item(2).ToString
Session("txtMiddleName") = datStudent.Item(3).ToString
Session("txtLastName") = datStudent.Item(4).ToString
Session("rblSex") = datStudent.Item(5).ToString
Session("txtStuInst") = datStudent.Item(6).ToString
Session("rblModerator") = datStudent.Item(7).ToString
Session("rblRoom") = datStudent.Item(8).ToString
Session("txtRoommate1First") = datStudent.Item(9).ToString
Session("txtRoommate1Middle") = datStudent.Item(10).ToString
Session("txtRoommate1Last") = datStudent.Item(11).ToString
Session("txtRoommate2First") = datStudent.Item(12).ToString
Session("txtRoommate2Middle") = datStudent.Item(13).ToString
Session("txtRoommate2Last") = datStudent.Item(14).ToString
Session("txtRoommate3First") = datStudent.Item(15).ToString
Session("txtRoommate3Middle") = datStudent.Item(16).ToString
Session("txtRoommate3Last") = datStudent.Item(17).ToString
Session("Amount") = datStudent.Item(38).ToString
End If
Session("date_submitted") = datStudent.Item(39).ToString
Session("Update") = "True"
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div style="text-align:center;">
<p>
Please note: If you are a staff member who would like to
register for the Graduate Fair as well, simply register
as a staff member and check the provided option on the
staff registration form indicating that you are attending
the Graduate Fair. ($<%=session("priceGradFair")%> fee
for the Graduate Fair will be added to your charge.)
</p>
<p><b>
Also, registration for each member is not complete until
all of his/her sections have been completed.
</b></p>
<asp:Panel ID="pnlStaff" runat="server" CssClass="aspPanelMembers" BorderColor="Black" BorderStyle="Double" BorderWidth="4px">
<h3>Staff Members in your group:</h3>
<asp:GridView ID="grdStaff" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" ShowHeader="false" OnSelectedIndexChanged="staff_changed" CssClass="aspGridView" OnRowDataBound="format_row">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:AccessDataSource ID="adsStaffProfiles" runat="server" />
<br />
<asp:Button ID="btnUpdateStaff" runat="server" Text="Update Selected Staff Member" Width="200px"
OnClick="UpdateStaff" Enabled="False" />
<br />
<asp:Button ID="btnRemoveStaff" runat="server" Text="Remove Selected Staff Member" Width="200px"
OnClick="RemoveStaff" Enabled="False" />
<asp:Label ID="lblRemoveStaff" runat="server" Text="(must finish all sections first)" Visible="False"></asp:Label>
<br />
<asp:Button ID="btnAddStaff" runat="server" Text="Add New Staff Member" PostBackUrl="~/ManagerMain/Staff/Default.aspx" Width="150px" Enabled="False" />
<asp:Label ID="lblAddStaff" runat="server"></asp:Label>
</asp:Panel>
<br />
<asp:Panel ID="pnlStudents" runat="server" CssClass="aspPanelMembers" BorderColor="Black" BorderStyle="Double" BorderWidth="4px">
<h3>Students in your group:</h3>
<asp:GridView OnSelectedIndexChanged="student_changed" ShowHeader="False" CssClass="aspGridView" ID="grdStudents" runat="server" OnRowDataBound="format_row" CellPadding="4" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:AccessDataSource ID="adsStudentProfiles" runat="server" />
<br />
<asp:Button ID="btnUpdateStudent" runat="server" Text="Update Selected Student" Width="170px"
OnClick="UpdateStudent" Enabled="False" />
<br />
<asp:Button ID="btnRemoveStudent" runat="server" Text="Remove Selected Student" Width="170px"
OnClick="RemoveStudent" Enabled="False" />
<asp:Label ID="lblRemoveStudent" runat="server" Text="(must finish all sections first)" Visible="False"></asp:Label>
<br />
<asp:Button ID="btnAddStudent" runat="server" Text="Add New Student" PostBackUrl="~/ManagerMain/Student/Default.aspx" Width="120px" Enabled="False" />
<asp:Label ID="lblAddStudent" runat="server"></asp:Label>
</asp:Panel>
<br />
<asp:Panel ID="pnlPayment" runat="server" CssClass="aspPanelPayment" BorderColor="Black" BorderStyle="Double" BorderWidth="4px">
<p>
Payment information for your group can be provided by
clicking on the button below.
</p>
<p>
<asp:Label ID="lblPayment" runat="server"
Text="<h3>(Incomplete)</h3>"
ForeColor="Red" />
</p>
<p>
<asp:Button ID="btnPay"
runat="server"
Text="Payment"
PostBackUrl="~/ManagerMain/PaymentInfo.aspx"/>
</p>
</asp:Panel>
<br />
<asp:LoginStatus ID="LoginStatus1" runat="server"
LogoutAction="Redirect"
LogoutPageUrl="~/Default.aspx"
OnLoggedOut="AbandonSession" />
</div>
</asp:Content>
MASTER PAGE:
<%@ Master Language="VB" %>
<%@ Register Assembly="SmartScroller" Namespace="sstchur.web.SmartNav" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript" language="javascript">
// Used to count the number of words in the description.
function WordCount()
{
var text = document.getElementById('ctl00_ContentPlaceHolder1_txtDescription');
var display = document.getElementById('ctl00_ContentPlaceHolder1_txtWords');
var pattern = /\s+/;
var word_array = text.value.split(pattern);
if (text.value == '')
display.value = "0 words";
else
display.value = word_array.length + " words";
if (word_array.length > 300)
display.style.color="red";
else
display.style.color="black";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title><%=Session("year")%> National McNair Research Conference & Graduate School Fair</title>
<link type="text/css" rel="Stylesheet" href="styles/styles.css" />
<link rel="shortcut icon" href="../../images/omsaicon.ico" type="image/x-icon" />
<script language="JavaScript" type="text/javascript"></script>
</head>
<body>
<div id="banner">
<div id="logo" align="center">
<img src="http://www.omsa.uiuc.edu/annualevents/mcnair_app/images/header2.gif" alt="Office of Minority Student Affairs" width="750" height="113" />
</div>
</div>
<a href="http://www.uiuc.edu/"
id="uiLogo"
target="_blank">
<img src="http://www.omsa.uiuc.edu/images/vsmlformal.gif"
alt="University of Illinois at Urbana-Champaign"
align="top"
border="0"
width="35"
height="46"/>
</a>
<div id="McNair">
<img src="http://www.omsa.uiuc.edu/annualevents/mcnair_app/images/mcnairsmall.JPG" alt="Ronald E. McNair" width="149" height="173" />
</div>
<div id="McNairLogo">
<img src="http://www.omsa.uiuc.edu/annualevents/mcnair_app/images/mcnairlogo.PNG" alt="McNair Logo" width="92" height="92" />
</div>
<form id="form1" runat="server">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server" />
<cc1:SmartScroller ID="SmartScroller1" runat="server" />
</form>
<br /><br />
</body>
</html>