星期日, 1月 24, 2010

DataList 自動編號

<div>
        <asp:DataList ID="DataListTestPaper" runat="server" DataKeyField="TestPaperItemID" DataSourceID="SqlDataSourceTestPaper" OnItemDataBound="DataList1_ItemDataBound" Width="736px" CellPadding="4" ForeColor="#333333">
            <ItemTemplate>
                        (<%# Container.ItemIndex + 1%>)
                        <!--試題id之後對答案要用到-->
                        <asp:Label ID="TestPaperItemIDLabel" runat="server" Text='<%# Eval("TestPaperItemID") %>' style="display: none;"></asp:Label>
                        
                        <asp:Label ID="TestPaerContentLabel" runat="server" Text='<%# Eval("TestPaerContent") %>'></asp:Label>
                        <asp:RadioButtonList ID="RadioButtonList1" runat="server" DataSourceID="SqlDataSourceOptions" DataTextField="TestPaperOptionsText" DataValueField="TestPaperOptionsID" RepeatDirection="Horizontal">
                        </asp:RadioButtonList>
                        <asp:SqlDataSource ID="SqlDataSourceOptions" runat="server" ConnectionString="<%$ ConnectionStrings:ELTestPaperConnectionString %>"
                            SelectCommand="SELECT TestPaperOptionsText, TestPaperOptionsID FROM TestPaperOptions WHERE (TestPaperOptionsPID = @pid)&#13;&#10;order by  newid() ">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="TestPaperItemIDLabel" Name="pid" PropertyName="Text" />
                            </SelectParameters>
                        </asp:SqlDataSource>
            </ItemTemplate>
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <SelectedItemStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <AlternatingItemStyle BackColor="White" />
            <ItemStyle BackColor="#E3EAEB" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        </asp:DataList><asp:SqlDataSource ID="SqlDataSourceTestPaper" runat="server" ConnectionString="<%$ ConnectionStrings:ELTestPaperConnectionString %>"
            SelectCommand="SELECT * FROM [TestPaper] where TestPaperCategoryID = @cid order by newid()&#13;&#10;">
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="1" Name="cid" QueryStringField="cid" />
            </SelectParameters>
        </asp:SqlDataSource>
    
    </div> 

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails