[英]ASP Repeater not showing data in the correct order
I am trying to use an ASP.NET repeater control to show employee data and I want to show this data sorted by employee name. 我正在尝试使用ASP.NET转发器控件来显示员工数据,并且我想显示按员工姓名排序的数据。 Even though the data I am getting from the database are in correct order after it bind to the repeater it shows in a different way (sort by employee id).
即使我从数据库中获取的数据在绑定到中继器之后按正确的顺序排列,它也会以不同的方式显示(按员工ID排序)。 How can this happen?
怎么会这样 Is there anyway I can stop this?
反正有我可以阻止这个吗?
<asp:Repeater ID="rptEmplist">
<HeaderTemplate>
<table class = "bootstrap-datatable datatable">
<thead>
<tr>
<th>Employee No</th>
<th>Employee Name</th>
<th>Department Name</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("Empnum") %></td>
<td><%# Eval("Name") %></td>
<td><%# Eval("DptName") %></td>
</tr>
</ItemTemplate>
<FooterTempalate>
</tbody>
</table>
</FooterTempalate>
</asp:Repeater>
C# databind method C#数据绑定方法
private void BindDataToGrid()
{
DataTable empdt = BSL.GetEmployeeList(); // Just a another layer to connect with DB.
rptEmplist.DataSource = empdt;// Data seems to be in the correct order in empdt
rptEmplist.DataBind();
}
Data retrieving C#: 数据检索C#:
public static DataTabe GetEmployeeList()
{
using(SqlCommand cmd = new SqlCommand("Get_EmpList"))
{
cmd.CommandType = CommandType.StoredProcedure;
return DSL.DBFactory.DBOperations.GetDataTable(cmd);
}
}
Database stored procedure: 数据库存储过程:
Create Proc Get_EmpList
AS
BEGIN
SELECT *
FROM Employee
ORDER BY Name
END
默认情况下,ASP.NET转发器不支持排序,您可以获取列表,然后添加linq查询以对列表进行排序
I had to remove "bootstrap-datatable datatable" from the table. 我不得不从表中删除“ bootstrap-datatable datatable”。 Even though this class making the table sortable, It is overwriting the original sort-order I am feeding the asp:Repeater
即使该类使表可排序,但它仍覆盖了原始的排序顺序,因此我正在输入asp:Repeater
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.