Hi Firuz,
Please refer the below code.
HTML
<div>
<asp:Panel ID="Panel1" runat="server" Width="720px" BackColor="#CCCCCC" HorizontalAlign="Center"
CssClass="panel">
<div class="LabelContainer">
<asp:Label ID="Label5" runat="server" Font-Bold="True" Font-Size="X-Large" Height="25px"
Text="Registration population"></asp:Label>
</div>
<div class="SecondLabelContainer">
<asp:Label ID="Label8" runat="server" Text="Label"></asp:Label>
</div>
<div class="IdContainer">
<asp:Label ID="Label1" runat="server" Text="Id"></asp:Label>
<asp:TextBox ID="ID" runat="server" Width="50"></asp:TextBox>
</div>
<div class="FirstNameContainer">
<asp:Label ID="Label3" runat="server" Text="FirstName"></asp:Label>
<asp:TextBox ID="FirstName" runat="server" Width="120"></asp:TextBox>
</div>
<div class="NameContainer">
<asp:Label ID="Label2" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="Name" runat="server" Width="120"></asp:TextBox>
</div>
<div class="LastNameContainer">
<asp:Label ID="Label4" runat="server" Text="LastName"></asp:Label>
<asp:TextBox ID="LastName" runat="server" Width="120"></asp:TextBox>
</div>
<div class="BirthdayContainer">
<asp:Label ID="Label6" runat="server" Text="Birthday"></asp:Label>
<asp:TextBox ID="Birthday" runat="server" Width="120"></asp:TextBox>
</div>
<div class="AdresContainer">
<asp:Label ID="Label7" runat="server" Text="Adress"></asp:Label>
<asp:TextBox ID="Adress" runat="server" Width="120"></asp:TextBox>
</div>
<div class="ButtonContainer">
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
<asp:Button ID="btnNext" runat="server" Text="Next" OnClick="btnNext_Click" />
<asp:Button ID="btnPrevious" runat="server" Text="Previous" OnClick="btnPrevious_Click" />
<asp:Button ID="btnFirst" runat="server" Text="First" OnClick="btnFirst_Click" />
<asp:Button ID="btnLast" runat="server" Text="Last" OnClick="btnLast_Click" />
</div>
</asp:Panel>
</div>
Code
public static int index = 0;
string str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
HttpContext.Current.Session["ArrayPos"] = null;
}
else
{
btnFirst.Enabled = false;
btnLast.Enabled = false;
btnNext.Enabled = false;
btnPrevious.Enabled = false;
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "INSERTINFO";
cmd.Parameters.AddWithValue("@FirstName", FirstName.Text);
cmd.Parameters.AddWithValue("@Name", Name.Text);
cmd.Parameters.AddWithValue("@LastName", LastName.Text);
cmd.Parameters.AddWithValue("@Birthday", Birthday.Text);
cmd.Parameters.AddWithValue("@Adress", Adress.Text);
cmd.Connection = con;
con.Open();
try
{
cmd.ExecuteNonQuery();
}
catch { }
con.Close();
}
public ArrayList GetInfo(string Name)
{
ArrayList list = null;
if (HttpContext.Current.Session["ArrayPos"] == null)
{
list = new ArrayList();
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "SEARCHINFO";
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Connection = con;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
list.Add(string.Join(";", rdr["Id"], rdr["FirstName"], rdr["Name"], rdr["LastName"], rdr["Birthday"], rdr["Address"]));
}
HttpContext.Current.Session["ArrayPos"] = list;
}
else
{
list = HttpContext.Current.Session["ArrayPos"] as ArrayList;
}
return list;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
if (Name.Text == "")
{
Label8.Text = "TextBox name is empty!";
Name.Focus();
}
else
{
Label8.Text = "";
ArrayList dt = GetInfo(Name.Text);
index = 0;
if (dt.Count > 0)
{
string[] pos = dt[index].ToString().Split(';');
ID.Text = pos[0].ToString();
FirstName.Text = pos[1].ToString();
Name.Text = pos[2].ToString();
LastName.Text = pos[3].ToString();
Birthday.Text = pos[4].ToString();
Adress.Text = pos[5].ToString();
}
else
{
Label8.Text = "People not saved in database!";
}
}
btnFirst.Enabled = true;
btnLast.Enabled = true;
btnNext.Enabled = true;
btnPrevious.Enabled = true;
}
protected void btnNext_Click(object sender, EventArgs e)
{
ArrayList dt = GetInfo(Name.Text);
btnPrevious.Enabled = true;
index = index + 1;
if (index < dt.Count)
{
string[] pos = dt[index].ToString().Split(';');
ID.Text = pos[0].ToString();
FirstName.Text = pos[1].ToString();
Name.Text = pos[2].ToString();
LastName.Text = pos[3].ToString();
Birthday.Text = pos[4].ToString();
Adress.Text = pos[5].ToString();
if (index == dt.Count - 1)
{
btnNext.Enabled = false;
}
else
{
btnNext.Enabled = true;
}
}
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
ArrayList dt = GetInfo(Name.Text);
btnNext.Enabled = true;
index = index - 1;
if (index < dt.Count)
{
string[] pos = dt[index].ToString().Split(';');
ID.Text = pos[0].ToString();
FirstName.Text = pos[1].ToString();
Name.Text = pos[2].ToString();
LastName.Text = pos[3].ToString();
Birthday.Text = pos[4].ToString();
Adress.Text = pos[5].ToString();
if (index == 0)
{
btnPrevious.Enabled = false;
}
else
{
btnPrevious.Enabled = true;
}
}
}
protected void btnFirst_Click(object sender, EventArgs e)
{
ArrayList dt = GetInfo(Name.Text);
btnNext.Enabled = true;
index = 0;
string[] pos = dt[index].ToString().Split(';');
ID.Text = pos[0].ToString();
FirstName.Text = pos[1].ToString();
Name.Text = pos[2].ToString();
LastName.Text = pos[3].ToString();
Birthday.Text = pos[4].ToString();
Adress.Text = pos[5].ToString();
if (index == 0)
{
btnPrevious.Enabled = false;
}
else
{
btnPrevious.Enabled = true;
}
}
protected void btnLast_Click(object sender, EventArgs e)
{
ArrayList dt = GetInfo(Name.Text);
btnNext.Enabled = false;
index = dt.Count - 1;
string[] pos = dt[index].ToString().Split(';');
ID.Text = pos[0].ToString();
FirstName.Text = pos[1].ToString();
Name.Text = pos[2].ToString();
LastName.Text = pos[3].ToString();
Birthday.Text = pos[4].ToString();
Adress.Text = pos[5].ToString();
if (index == 0)
{
btnPrevious.Enabled = false;
}
else
{
btnPrevious.Enabled = true;
}
}
Screenshot