Hello experts,
We have an app that prompts employees to enter his/her empID.
Once the employee enters his/her ID, the VB/Stored Proc checks the ID to determine if user has entered his/her information from previous year.
If no, the user gets a blank page to enter his/her data.
If user had entered data the previous year, our objective is to have data populate the GridView control giving the user the opportunity to review data and make changes if necessary.
The code largely works when populating data outside of GridView.
However, GridView is not getting populated with the two sourcename and spousename.
Obviously, it is not recognizing textboxes from GridView.
Any ideas how to resolve this?
My abbreviated code below. Thanks a lot in advnce
Sorry for the long code.
Stored Proc
ALTER PROCEDURE [dbo].[ValidateEmpID]
@empID varchar(50)
AS
BEGIN
SET NOCOUNT OFF;
SELECT employeeName, email, emptitle, EmpID,
CASE WHEN YEAR(d.dateCreated) = YEAR(getdate()) -1 THEN 1 ELSE 0 END as previousYear,
CASE WHEN YEAR(d.dateCreated) = YEAR(getdate()) THEN 1 ELSE 0 END as thisYear
FROM Employees e
INNER JOIN dateDetails d on e.employeeID = d.EmployeeID
INNER JOIN SourceDetails so on e.employeeID = so.EmployeeID
INNER JOIN SpouseDetails sp on e.employeeID = sp.employeeID
WHERE EmpID=@empID
END
//HTML
<div class="table-responsive"><table class="table"><tr><td><div class="form-group"><label for="lblEname"><span style="font-weight:bold;font-size:16px;color:#000000;">Employee Name</span><span style="color:#ff0000">*</span></label><asp:TextBox ID="txteName" placeholder="Employee name..." style="width:200px;" class="form-control" runat="server"></asp:TextBox><asp:RequiredFieldValidator id="RequiredFieldValidator2" Font-Bold="true"
SetFocusOnError="true" runat="server"
ErrorMessage="*" ControlToValidate="txteName" /><br /></div></td><td><div class="form-group"><label id="lblTitle"><span style="font-weight:bold;font-size:16px;color:#000000;">Your title</span><span style="color:#ff0000">*</span></label><asp:TextBox ID="txttitle" placeholder="Employee title..." style="width:200px;" class="form-control" runat="server"></asp:TextBox><asp:RequiredFieldValidator id="RequiredFieldValidator3" Font-Bold="true"
SetFocusOnError="true" runat="server"
ErrorMessage="*" ControlToValidate="txttitle" /></div> </td><td><div class="form-group"><label id="lblEmail"><span style="font-weight:bold;font-size:16px;color:#000000;">Your email address</span><span style="color:#ff0000">*</span></label><asp:TextBox ID="txtemail" placeholder="Employee email..." style="width:200px;" class="form-control" runat="server"></asp:TextBox><asp:RequiredFieldValidator id="RequiredFieldValidator4" Font-Bold="true"
SetFocusOnError="true" runat="server"
ErrorMessage="*" ControlToValidate="txtemail" /></div></td></tr></table></div><table class="table"><tr><td><asp:gridview ID="Gridview1" RowStyle-Wrap="false" gridlines="None" CssClass="responsiveTable1" runat="server" ShowFooter="true" AutoGenerateColumns="false" onrowdatabound="Gridview1_RowDataBound" OnRowDeleting="Gridview1_RowDeleting"><Columns><asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" /><asp:TemplateField HeaderText="Name"><headerstyle horizontalalign="Left" /><ItemTemplate><asp:TextBox ID="txtsourcename" Text='<%# Eval("sourcename") %>' placeholder="Name...(e.g, Jane Doe)" runat="server" style="width:375px;" AutoPostBack="true" class="form-control textClass" OnTextChanged="txtsourcename_TextChanged"></asp:TextBox><br /><asp:CheckBox ID="grid1Details" ClientIDMode="Static" runat="server" Checked="false" AutoPostBack="true" OnCheckedChanged="Grid1CheckChanged" /><span style="color:#ff0000">*Check this box if N/A</span></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Address"><ItemStyle HorizontalAlign="Left"></ItemStyle><ItemTemplate><asp:TextBox ID="txtsourceaddress" Text='<%# Eval("sourceaddress") %>' placeholder="Address..." runat="server" style="width:375px;" class="form-control textClass"></asp:TextBox><br /><br /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText=""><ItemTemplate><asp:Button ID="ButtonAdd" runat="server" Text="Add another row if needed"
onclick="ButtonAdd_Click" CssClass="grvAddButton" /><br /><br /><br></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText=""><ItemTemplate><asp:Button ID="sourceDelete" runat="server" Text="Delete" CommandName="Delete"
CssClass="grvDelButton" OnClientClick="return confirm('Are you sure you want to remove this row?')" /> <br /><br /><br /></ItemTemplate></asp:TemplateField> </Columns></asp:gridview></td></tr></table>
//VB
Protected Sub txtEmpID_TextChanged(sender As Object, e As EventArgs) Handles txtEmpID.TextChanged
If Not String.IsNullOrEmpty(txtEmpID.Text) Then
Dim Conn As SqlConnection
'Read in connection String
Conn = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Conn.Open()
Dim cmd As New SqlCommand("ValidateEmpID", Conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@empID", txtEmpID.Text)
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.HasRows Then
'Employee exists'
dr.Read()
checkusername.Visible = True
dprocessed.Visible = True
If dr("previousYear").ToString() = "1" Then
imgstatus.ImageUrl = "images/NotAvailable.jpg"
lblStatus.Text = "Please verify your information for accuracy. Then complete rest of the form."
lblStatus.ForeColor = System.Drawing.Color.Red
System.Threading.Thread.Sleep(300)
txteName.Text = dr("employeeName").ToString()
txttitle.Text = dr("empTitle").ToString()
txtemail.Text = dr("email").ToString()
txtEmpID.Text = dr("empID").ToString()
Dim currentRow As GridViewRow = CType((CType(sender, TextBox)).Parent.Parent.Parent.Parent, GridViewRow)
Dim txtsource As TextBox = CType(currentRow.FindControl("txtsourcename"), TextBox)
txtsource.Text = dr("sourcename").ToString()
Dim txtsource As TextBox = CType(currentRow.FindControl("txtspousename"), TextBox)
txtspouse.Text = dr("spousename").ToString()
ElseIf dr("thisYear").ToString() = "1" Then
imgstatus.ImageUrl = "images/NotAvailable.jpg"
lblStatus.Text = "You have already completed this Disclosure form. Please close the form. If you feel there is a mistake, please contact Clerk at xxx-xxx-xxxx"
lblStatus.ForeColor = System.Drawing.Color.Red
System.Threading.Thread.Sleep(300)
txteName.Text = dr("employeeName").ToString()
txttitle.Text = dr("empTitle").ToString()
txtemail.Text = dr("email").ToString()
txtEmpID.Text = dr("empID").ToString()
txteName.Enabled = False
txttitle.Enabled = False
txtemail.Enabled = False
txtEmpID.Enabled = False
GridPanels.Enabled = False
dprocessed.Visible = True
btnNext.Enabled = False
Else
'not this year, nor the previous year'
End If
Else
checkusername.Visible = True
dprocessed.Visible = True
imgstatus.ImageUrl = "images/Icon_Available.gif"
lblStatus.Text = "Proceed to complete entire form"
lblStatus.ForeColor = System.Drawing.Color.Red
System.Threading.Thread.Sleep(300)
txteName.Text = ""
txttitle.Text = ""
txtemail.Text = ""
End If
Else
checkusername.Visible = False
End If
End Sub