【发布时间】:2021-10-17 23:35:11
【问题描述】:
我正在尝试获取表类别,并且基于该表类别,该类别的多个详细信息必须在以下类别下自动获取,但不幸的是,在该单个类别下创建了多个表。
首先,我在 DB 上创建了 tbl_category(ID{PK}, catName) 表。然后创建 tbl_categoryDetails(ID{PK}, catId{FK}, catDetails)。所以我需要单个类别下的多个 categoryDetails 字段。
那么我必须逐个获取这个 catName 及其详细信息。我已经附上了静态表,我需要这种方式来获取表数据Static Table Image。
但不幸的是,我以这种方式获取数据My Dynamic Table Image。 categoryName 获取多次,但我想要一次。我正在使用中继器控件从数据库中获取数据。请帮我解决这个问题。
我的 Forms.aspx 代码在这里:
<asp:Repeater ID="rptr_form" runat="server">
<ItemTemplate>
<section class="about">
<div class="container">
<div class="row no-gutters d-flex justify-content-center">
<div class="flex-column justify-content-center about-content minwidth">
<div class="section-title">
<div class="mycontent-center">
<h2 style="margin-bottom: -5px;" data-toggle="collapse" role="button" href="#collapseExample19" aria-expanded="false" aria-controls="collapseExample19"><%#Eval("form_categoryname") %>   <i class="fa fa-chevron-circle-down" aria-hidden="true"></i></h2>
<br />
<div class="content-style collapse tbl-scroll" id="collapseExample19">
<table class="table table-striped">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">No</th>
<th scope="col">Bangla</th>
<th scope="col">English</th>
</tr>
</thead>
<tbody>
<tr class="table-info">
<td><%#Eval("form_details") %></td>
<td><%#Eval("form_no") %></td>
<td><a href="<%# "../" + Eval("form_bengali_path") %>" target="_blank">
<img src="assets/image/pdf.jpg" style="height: 30px; width: 48px;" /></a></td>
<td class="center"><a href="<%# "../" + Eval("form_english_path") %>" target="_blank">
<img src="assets/image/pdf.jpg" style="height: 30px; width: 48px;" /></a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</ItemTemplate>
</asp:Repeater>
我的 Forms.aspx.cs 代码在这里:
protected void AllFormLoad()
{
try
{
using (SqlConnection con = new SqlConnection(strcon))
{
SqlCommand cmd = new SqlCommand("spFormDetailsFetch", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
rptr_form.DataSource = dt;
rptr_form.DataBind();
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}
}
Sql 查询
select D.ID, C.form_categoryname, D.form_details, D.form_no, D.form_bengali_path, D.form_english_path from tbl_form_details D inner join tbl_form_category C on D.form_categoryId = C.ID order by form_categoryname
【问题讨论】:
标签: c# asp.net webforms fetch dynamic-tables