2016-06-14 94 views
2

我想使用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 
+0

显示查询或装载员工的SP。 – Mairaj

+0

如果中继器没有以“正确的顺序”显示数据,那么您没有按照正确的顺序排序数据。 –

+0

你是否检查过'empdt'中的数据是否正常? –

回答

0

我必须从表中删除“bootstrap-datatable datatable”。尽管该类使得表排序,它是覆盖原来的排序顺序我喂养的asp:直放站

More about datatable

0

ASP.NET中继器不支持排序,你可以获取列表和th en添加linq查询以订购该列表

+0

我不认为你已经理解了这个问题 –