ASP.net code C# ดึง data จาก MS SQL โดย repeater

posted on 03 Nov 2009 16:27 by techinnoreview  in MITT
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
    <HeaderTemplate>
    <table width="480" cellspacing="0">
    <tr bgcolor="red">
    <td>Id</td>
    <td>Name</td>
    <td>Price</td>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr bgcolor="white">
    <td><%#Eval("ProductID") %><br/></td>
    <td><%#Eval("ProductName") %><br/></td>
    <td><%#Eval("Unitprice") %><br/></td>
    </tr>
    </ItemTemplate>
    <AlternatingItemTemplate>
        </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr bgcolor="navy">
    <td><%#Eval("ProductID") %><br/></td>
    <td><%#Eval("ProductName") %><br/></td>
    <td><%#Eval("Unitprice") %><br/></td>
    </tr>
    </AlternatingItemTemplate>
    <FooterTemplate>
    <tr bgcolor="red"><td>END</td><td>END</td><td>END</td></tr>
    </table>
    </FooterTemplate>
    </asp:Repeater>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindAHu %>" 
        
        SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories] ORDER BY [CategoryName], [CategoryID]">
    </asp:SqlDataSource>
    <br />
    <br />
    <asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="SqlDataSource1" DataTextField="ProductName" 
        DataValueField="CategoryID" Height="16px" Width="326px">
    </asp:DropDownList>
    </form>
</body>
</html>

Comment



smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry

Tweet