To display student details, you can utilize a repeater control:
<asp:Repeater ID="rptStudentDetails" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="1">
<tr style="background-color: #fa7b16; color: #FFF; height: 35px;" align="center">
<th>
Student Name
</th>
<th>
Class
</th>
<th>
Age
</th>
<th>
Gender
</th>
<th>
Address
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color: white;" align="center">
<td>
<%#Eval("StudentName") %>
</td>
<td>
<%#Eval("Class") %>
</td>
<td>
<%#Eval("Age") %>
</td>
<td>
<%#Eval("Gender") %>
</td>
<td>
<%#Eval("Address") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Button ID="btnLoadMore" runat="server" Text="Load More Data" OnClick="btnLoadMore_Click" />
In the code-behind file (.cs)
protected void btnLoadMore_Click(object sender, EventArgs e)
{
int numVal = Convert.ToInt32(ViewState["num"]) + 2;
BindRepeater(numVal);
ViewState["num"] = numVal;
}
private void BindRepeater(int numOfRows)
{
DataTable dt = new DataTable();
SqlCommand cmd = null;
SqlDataAdapter adp = null;
try
{
int rCount = rowCount();
if (numOfRows > rCount)
{
btnLoadMore.Visible = false;
}
cmd = new SqlCommand("GetStudentDetails_SP", con);
cmd.Parameters.AddWithValue("@topVal", numOfRows);
cmd.CommandType = CommandType.StoredProcedure;
adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
rptStudentDetails.DataSource = dt;
rptStudentDetails.DataBind();
}
}
}
For more information, visit the following links:
Asp.Net Load more data records on button click in Repeater Control from sql server table
LOAD MORE DATA RECORDS ON BUTTON CLICK IN ASP.NET REPEATER FROM SQL SERVER TABLE