Hi RayMilhon,
Please refer the sample below.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ConnectionStrings:constr%>"
SelectCommand="SELECT * FROM Customers"></asp:SqlDataSource>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="OnSearch" />
<hr />
<asp:TextBox ID="txtId" runat="server" /><br />
<asp:TextBox ID="txtName" runat="server" /><br />
<asp:TextBox ID="txtCountry" runat="server" /><br />
<asp:Button ID="btnNext" runat="server" Text="Next" OnClick="OnNext" />
<asp:HiddenField ID="hfIndex" runat="server" Value="0" />
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
}
protected void OnSearch(object sender, EventArgs e)
{
DataSourceSelectArguments args = new DataSourceSelectArguments();
DataView view = (DataView)SqlDataSource1.Select(args);
DataTable dt = view.ToTable();
Session["Data"] = dt;
txtId.Text = dt.Rows[Convert.ToInt32(hfIndex.Value)]["CustomerId"].ToString();
txtName.Text = dt.Rows[Convert.ToInt32(hfIndex.Value)]["Name"].ToString();
txtCountry.Text = dt.Rows[Convert.ToInt32(hfIndex.Value)]["Country"].ToString();
hfIndex.Value = (Convert.ToInt32(hfIndex.Value) + 1).ToString();
}
protected void OnNext(object sender, EventArgs e)
{
DataTable dt = (DataTable)Session["Data"];
txtId.Text = dt.Rows[Convert.ToInt32(hfIndex.Value)]["CustomerId"].ToString();
txtName.Text = dt.Rows[Convert.ToInt32(hfIndex.Value)]["Name"].ToString();
txtCountry.Text = dt.Rows[Convert.ToInt32(hfIndex.Value)]["Country"].ToString();
hfIndex.Value = (Convert.ToInt32(hfIndex.Value) + 1).ToString();
if (Convert.ToInt32(hfIndex.Value) == dt.Rows.Count)
{
hfIndex.Value = "0";
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
End Sub
Protected Sub OnSearch(ByVal sender As Object, ByVal e As EventArgs)
Dim args As DataSourceSelectArguments = New DataSourceSelectArguments()
Dim view As DataView = CType(SqlDataSource1.[Select](args), DataView)
Dim dt As DataTable = view.ToTable()
Session("Data") = dt
txtId.Text = dt.Rows(Convert.ToInt32(hfIndex.Value))("CustomerId").ToString()
txtName.Text = dt.Rows(Convert.ToInt32(hfIndex.Value))("Name").ToString()
txtCountry.Text = dt.Rows(Convert.ToInt32(hfIndex.Value))("Country").ToString()
hfIndex.Value = (Convert.ToInt32(hfIndex.Value) + 1).ToString()
End Sub
Protected Sub OnNext(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable = CType(Session("Data"), DataTable)
txtId.Text = dt.Rows(Convert.ToInt32(hfIndex.Value))("CustomerId").ToString()
txtName.Text = dt.Rows(Convert.ToInt32(hfIndex.Value))("Name").ToString()
txtCountry.Text = dt.Rows(Convert.ToInt32(hfIndex.Value))("Country").ToString()
hfIndex.Value = (Convert.ToInt32(hfIndex.Value) + 1).ToString()
If Convert.ToInt32(hfIndex.Value) = dt.Rows.Count Then
hfIndex.Value = "0"
End If
End Sub
Screenshot