我从数据库中获取图像并在网页上显示图像,如果图像更多,我想显示更多图像按钮,如果用户点击显示更多按钮,还想在同一网页上自动显示更多图像在ASP.Net
答案 0 :(得分:1)
您可以使用转发器:
<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" />
在代码隐藏的.cs文件中
protected void btnLoadMore_Click(object sender, EventArgs e)
{
//On every click of this button it will add 2 to the ViewState["num"] whose value was set to 2 initially on page load. So numval is 4 now.
int numVal = Convert.ToInt32(ViewState["num"]) + 2;
//Now pass numVal whose value is 4 to the BindRepeater function to get 4 rows.
BindRepeater(numVal);
//Set ViewState["num"] is equal to the numVal i.e. 4 so that when we again click this button it will be 4 + 2= 6 and so on.
ViewState["num"] = numVal;
}
private void BindRepeater(int numOfRows)
{
DataTable dt = new DataTable();
SqlCommand cmd = null;
SqlDataAdapter adp = null;
try
{
//get number rows in table by calling the rowCount function i created.
int rCount = rowCount();
// hide the "Load More Data button" if the number of request rows becomes greater than the rows in table
if (numOfRows > rCount)
{
btnLoadMore.Visible = false;
}
cmd = new SqlCommand("GetStudentDetails_SP", con);
//Passs numOfRows variable value to stored procedure to get desired number of rows
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();
}
}
}
有关详情,请参阅以下网址:
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