0

我正在使用 datalist 来显示数据。数据是有 4 个选项的测试问题。我在数据列表中显示了 50 个问题。

通过使用 ItemDataBound 事件 - 我只向用户显示一个带有 4 个选项的问题。剩下的问题是看不见的。在 Itemdatabound 事件中 - 我将 id 分配给单选按钮。而且 id 也没有分配给数据列表,它显示不同的 id。

  <div class="widget">
                <div class="widget-header" align="center" style="background: #4a98c9; color: #FFFFFF;">
                    <h4>
                        <asp:Label ID="Label5" runat="server" Text="Question : "></asp:Label>
                        <asp:Label ID="lblQuestionNo" runat="server" Text="0 of 0"></asp:Label></h4>
                    <asp:HiddenField ID="HdCurrentQuestSlNo" runat="server" />
                    <asp:HiddenField ID="HdfMinTime" runat="server" />
                    <asp:HiddenField ID="HdfSecTime" runat="server" />
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                    <asp:HiddenField ID="HdfQSlNo" runat="server" />
                    <asp:HiddenField ID="HdQuestCount" runat="server" Value="0"/>
                </div>
                <div class="widget-content">
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <asp:Panel ID="PanelQuestBlock" runat="server" ScrollBars="Vertical" Width="100%" Height="325px">
                                <asp:DataList runat="server" ID="DataListQuestion" 
                                    onitemdatabound="DataListQuestion_ItemDataBound" 
                                    onitemcreated="DataListQuestion_ItemCreated">
                                    <ItemTemplate>
                                        <div class="questdisplayId" id="divQuestBlock" runat="server">
                                            <div>
                                                <asp:HiddenField ID='HdSlNo' runat="server" Value='<%# Eval("SlNo") %>' ClientIDMode="Static"/>
                                                <asp:HiddenField ID="HdUserQuestId" runat="server" Value='<%# Eval("UserQuestionId") %>' ClientIDMode="Static"/>
                                                <asp:HiddenField ID="HdTotalOptions" runat="server" Value='<%# Eval("TotalOptions") %>' ClientIDMode="Static"/>
                                                <asp:HiddenField ID="HdQuestAnsweredTimeSecs" runat="server" Value='<%# Eval("AnsweredTimeSecs") %>' ClientIDMode="Static"/>
                                                <asp:HiddenField ID="HdOptionAnswered" runat="server" Value='<%# Eval("OptionAnswered") %>' ClientIDMode="Static"/>
                                            </div>
                                            <div>
                                                <asp:Label ID="Question" runat="server" Text='<%# Eval("Question") %>'></asp:Label>
                                            </div>
                                            <div class="answer-row" id="divOption1" runat="server">
                                                <asp:RadioButton ID="Option1" runat="server" GroupName="Answer" value="1" Text='<%# Eval("Option1") %>'
                                                    CssClass="rdbtn" Style="vertical-align: middle" ClientIDMode="Static"/>
                                                <asp:Label ID="lblOpt1" runat="server" Text=""></asp:Label>
                                            </div>
                                            <div class="answer-row" id="divOption2" runat="server">
                                                <asp:RadioButton ID="Option2" runat="server" GroupName="Answer" value="2" Text='<%# Eval("Option2") %>'
                                                    CssClass="rdbtn" Style="vertical-align: middle" ClientIDMode="Static"/>
                                                <asp:Label ID="lblOpt2" runat="server" Text=""></asp:Label>
                                            </div>
                                            <div class="answer-row" id="divOption3" runat="server">
                                                <asp:RadioButton ID="Option3" runat="server" GroupName="Answer" value="3" Text='<%# Eval("Option3") %>'
                                                    CssClass="rdbtn" Style="vertical-align: top; left: auto;" ClientIDMode="Static"/>
                                                <asp:Label ID="lblOpt3" runat="server" Text=""></asp:Label>
                                            </div>
                                            <div class="answer-row" id="divOption4" runat="server">
                                                <asp:RadioButton ID="Option4" runat="server" GroupName="Answer" value="4" Text='<%# Eval("Option4") %>'
                                                    CssClass="rdbtn" Style="vertical-align: text-top" ClientIDMode="Static"/>
                                                <asp:Label ID="lblOpt4" runat="server" Text=""></asp:Label>
                                            </div>  
                                            <div class="answer-row" id="divOption5" runat="server">
                                                <asp:RadioButton ID="Option5" runat="server" GroupName="Answer" value="4" Text='<%# Eval("Option5") %>'
                                                    CssClass="rdbtn" Style="vertical-align: text-top" ClientIDMode="Static"/>
                                                <asp:Label ID="lblOpt5" runat="server" Text=""></asp:Label>
                                            </div>                                               
                                        </div>
                                    </ItemTemplate>
                                </asp:DataList>
                            </asp:Panel>
                            <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                <ContentTemplate>
                                    <div class="row">
                                        <div class="span8" align="center">                                                
                                            <asp:Button ID="btnClear" runat="server" Text="Clear Selection" 
                                                CssClass="btn btn-warning" OnClientClick="Clearbutton();" 
                                                />
                                            <asp:Button ID="btnSave" runat="server" Text="Save & Next" CssClass="btn btn-success" OnClientClick="Savebutton()"/>
                                        </div>
                                        <div class="span4" align="center">
                                        <asp:Button ID="btnReview" runat="server" Text="Mark Review & Next" CssClass="btn btn-info" OnClientClick="Reviewbutton()"/>
                                            <asp:Button ID="btnFinish" runat="server" Text="Finish" CssClass="btn btn-danger" OnClientClick="Finishbutton()"/>
                                        </div>
                                    </div>
                                </ContentTemplate>
                                <Triggers>
                                    <asp:AsyncPostBackTrigger ControlID="btnReview" />
                                    <asp:AsyncPostBackTrigger ControlID="btnClear" />
                                    <asp:AsyncPostBackTrigger ControlID="btnSave" />
                                </Triggers>
                            </asp:UpdatePanel>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="DataListQuestion" />
                        </Triggers>
                    </asp:UpdatePanel>
                </div>
            </div>

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {                
HiddenField HdSlNo = (HiddenField)e.Item.FindControl("HdSlNo");
                RadioButton Option1 = (RadioButton)e.Item.FindControl("Option1");
                RadioButton Option2 = (RadioButton)e.Item.FindControl("Option2");
                RadioButton Option3 = (RadioButton)e.Item.FindControl("Option3");
                RadioButton Option4 = (RadioButton)e.Item.FindControl("Option4");
                RadioButton Option5 = (RadioButton)e.Item.FindControl("Option5");

                Option1.ID = "rdbtnoption1_" + HdSlNo.Value.ToString();
                Option2.ID = "rdbtnoption2_" + HdSlNo.Value.ToString();
                Option3.ID = "rdbtnoption3_" + HdSlNo.Value.ToString();
                Option4.ID = "rdbtnoption4_" + HdSlNo.Value.ToString();
                Option5.ID = "rdbtnoption5_" + HdSlNo.Value.ToString();
}

在我的设计页面代码中,使用 Datalist 我绑定了 50 个问题。在约束自己的同时,我隐藏了 2 到 50 个问题。问题 1 仅可见。我尝试使用事件数据绑定和行创建为每个问题和选项提供动态 ID。首先它出现错误,之后我将控件的属性更改为 ClientIDMode="Static"。它显示了不同的 id。但是,如果我再次单击任何按钮事件,它会清除 id's.again 它只显示旧 id。

4

0 回答 0