我想使用ASP.NET中继器控件来显示员工数据,我想显示这个数据按员工姓名排序。即使从数据库获得的数据在绑定到中继器后按正确的顺序显示,它也会以不同的方式显示(按员工ID排序)。这怎么会发生?无论如何,我可以阻止这个吗?ASP中继器没有以正确的顺序显示数据
<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#数据绑定方法
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();
}
数据检索C#:
public static DataTabe GetEmployeeList()
{
using(SqlCommand cmd = new SqlCommand("Get_EmpList"))
{
cmd.CommandType = CommandType.StoredProcedure;
return DSL.DBFactory.DBOperations.GetDataTable(cmd);
}
}
数据库存储过程:在默认情况下
Create Proc Get_EmpList
AS
BEGIN
SELECT *
FROM Employee
ORDER BY Name
END
显示查询或装载员工的SP。 – Mairaj
如果中继器没有以“正确的顺序”显示数据,那么您没有按照正确的顺序排序数据。 –
你是否检查过'empdt'中的数据是否正常? –