转发器格式

时间:2012-02-04 08:58:49

标签: c# asp.net

我在使用转发器时非常模糊

是不是在sql的第一行显示数据?

我的数据库中的数据

userName  Phone
Admin     admin
roy       012345678
ken       012345678

从我的代码输出

userName:Admin

电话:admin

------------------------------------

userName:roy

电话:012345678

------------------------------------

userName:ken

电话:012345678

------------------------------------

预期输出

userName: roy
phone: 012345678
------------------------------------
userName: ken
phone: 012345678
----------------------
下面的

是我的代码

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" >

        <ItemTemplate>

    Course Name: <%#DataBinder.Eval(Container.DataItem, "subject" )%>

    <br />

    Subject Info: <%#DataBinder.Eval(Container.DataItem,"subjectIntroduction")%>

    <hr />

</asp:Repeater>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [subject], [subjectIntroduction] FROM [courseSubjectTable]">    

</asp:SqlDataSource>

1 个答案:

答案 0 :(得分:1)

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" >

     <ItemTemplate>
userName:&nbsp;
    <%#DataBinder.Eval(Container.DataItem, "subject" ) +"<br/>"%>
phone:&nbsp;
    <%#DataBinder.Eval(Container.DataItem,"subjectIntroduction")  + "<hr/>"%>
</ItemTemplate>
</asp:Repeater>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [subject], [subjectIntroduction] FROM [courseSubjectTable]">    

</asp:SqlDataSource>

使用此选项不显示admin:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [subject], [subjectIntroduction] FROM [courseSubjectTable] where userName <> 'Admin'">