【发布时间】:2021-03-18 14:04:10
【问题描述】:
净。我想要一个像 recyclerview 这样的东西,你在 aspx 文件中有 1 张卡,它根据数据库中的条目数不断重复。因此,如果我的数据库表假设有 3 个特定名称的条目,那么页面中应该有 3 张卡片。
这是我到目前为止所做的: 在我的 .aspx 文件中:
<div class="item-card9">
<a href="info_page.aspx" class="text-dark">
<h4 class="font-weight-semibold mt-1">
<asp:Label ID="Label1" runat="server" >
<%# uni_name %>
</asp:Label>
</h4>
</a>
</div>
对于我的 aspx.cs:-
public string uni_name;
SqlCommand cmd = new SqlCommand();
//SQL connection here
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
cmd.CommandText = //select statement here
cmd.Connection = con;
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
uni_name = rd["name"].ToString();
}
this.DataBind();
con.Close();
}
到目前为止,我只能从我的数据库中获取 1 个条目,但我希望它一直重复到数据库结束。
【问题讨论】: