Greetings experts and happy new year
We using dynamic textboxes which allows us to add additional rows when needed.
I got most of my help from you experts to get this project working.
Thank you very much much.
Now, I have a new requirement that when the page loads and user enters his/her employeeID, all records from previous year should populate the boxes if they exist.
I have written a stored procedure to get all records belonging to a particular employee based on empID. It works.
Then I am calling this stored proc in my VB.
The problem is that when a user logs in, his/her records from previous year is not populating the gridview boxes.
Can someone please tell me what I am doing wrong?
Many thanks in advance
//Stored Procedure
ALTER PROCEDURE [dbo].[uspGetAllRecs]
@empID nvarchar(50)
AS
begin
SET NOCOUNT ON;
select ROW_Number() OVER (ORDER BY(SELECT 0)) ID, e.empid,s.sourcename As sourcename, d.dateCreated, s.sourceaddress As sourceaddress
FROM Employees e INNER JOIN SourceDetails s ON e.EmployeeID = s.EmployeeID
INNER JOIN dateDetails d ON s.EmployeeID = e.employeeID
WHERE d.dateCreated >= DATEADD(year, DATEDIFF(year, 0, GETDATE()) - 1, 0)
AND d.dateCreated < DATEADD(year, DATEDIFF(year, 0, GETDATE()), 0) AND e.empID = @empID
end
<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>
<%-- <asp:CommandField ShowDeleteButton="True"><ControlStyle CssClass="grvDelButton" /></asp:CommandField>--%>
</Columns>
</asp:GridView>
Private Sub fillSourceRecords(ByVal empID As String)
Dim conn As SqlConnection = New SqlConnection(connStr)
Dim sourcecmd As SqlCommand = New SqlCommand("uspGetAllRecs", conn)
sourcecmd.CommandType = CommandType.StoredProcedure
sourcecmd.Parameters.AddWithValue("@empID", empID)
Dim sda As SqlDataAdapter = New SqlDataAdapter(sourcecmd)
Dim dtPreviousRecords As DataTable = New DataTable()
sda.Fill(dtPreviousRecords)
If dtPreviousRecords.Rows.Count > 0 Then
Gridview1.DataSource = dtPreviousRecords
Gridview1.DataBind()
ViewState("CurrentTable") = dtPreviousRecords
End If
End Sub