在第一个ListView中选择一行后,如何使第二个ListView显示(可见)? [英] How to make this second ListView displayed (visible) after selecting a row in the first ListView?

查看:59
本文介绍了在第一个ListView中选择一行后,如何使第二个ListView显示(可见)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ASP.NET的新开发人员,必须创建测验引擎应用程序.我正在使用三个LiveView控件来显示:
1.测验信息
2.问题信息(基于第一个ListView上选择的测验)
3.回答信息(基于第二个ListView上选择的问题)

我具有以下数据库设计:

 QuizContent表:ID,QuizID,QuestionID,AnswerID
测验表:QuizID,标题,说明
问题表:QuestionID,Question,QuestionOrder,AnswerExplanation
答案表:AnswerID,答案



我现在想要的是以下内容:当用户(是管理员)进入测验引擎页面时,他应该只看到第一个主要是有关测验信息的ListView.当他选择一个测验时,将显示第二个ListView以及所选测验的问题信息.当他选择一个问题时,将显示第三个ListView以及该选择问题的答案信息.

**那怎么办?**

我知道我不应该发布过多的代码或信息,但我必须这样做以使其清楚:

<asp:ListView ID="ListView1" runat="server" DataKeyNames="QuizID" 
                DataSourceID="SqlDataSource1" InsertItemPosition="LastItem" >
                
                <EditItemTemplate>
                    <tr style="">
                        <td>
                            <asp:ImageButton ID="UpdateButton" ImageUrl="Images/icons/update24.png" ToolTip="Update"  runat="server" CommandName="Update" />
                            
                            <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/cancel324.png" ToolTip="Cancel" runat="server" CommandName="Cancel" />
                        </td>
                        <td>
                            <asp:TextBox ID="TitleTextBox" runat="server" Text=''<%# Bind("Title") %>'' />
                        </td>
                        <td>
                            <asp:TextBox ID="DescriptionTextBox" runat="server" 
                                Text=''<%# Bind("Description") %>'' />
                        </td>
                    </tr>
                </EditItemTemplate>
                <EmptyDataTemplate>
                    <table id="Table1"  runat="server" style="">
                        <tr>
                            <td>
                                No data was returned.</td>
                        </tr>
                    </table>
                </EmptyDataTemplate>
                <InsertItemTemplate>
                    <tr style="">
                        <td>
                            <asp:ImageButton ID="InsertButton" ImageUrl="Images/icons/add24.png" ToolTip="Add"  runat="server" CommandName="Insert" />
                        
                            <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/clear24.png" ToolTip="Cancel"  runat="server" CommandName="Cancel" />
                        </td>

                        <%--<td>
                             </td>--%>
                        <td>
                            <asp:TextBox ID="TitleTextBox" runat="server" Text=''<%# Bind("Title") %>'' />
                        </td>
                        <td>
                            <asp:TextBox ID="DescriptionTextBox" runat="server" 
                                Text=''<%# Bind("Description") %>'' />
                        </td>
                    </tr>
                </InsertItemTemplate>
                <ItemTemplate>
                    <tr style="">
                        <td>
                            <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete"  runat="server" CommandName="Delete" />

                            <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit"  runat="server" CommandName="Edit" />

                            <asp:ImageButton ID="SelectButton" ImageUrl="Images/icons/select.png" ToolTip="Select"  runat="server" CommandName="Select" />
                            <%--<asp:Button ID="SelectButton" runat="server" CommandName="Select" Text="Select" />--%>
                        </td>
                        <%--<td>
                            <asp:Label ID="QuizIDLabel" runat="server" 
                                Text=''<%# Eval("QuizID") %>'' />
                        </td>--%>
                        <td>
                            <asp:Label ID="TitleLabel" runat="server" Text=''<%# Eval("Title") %>'' />
                        </td>
                        <td>
                            <asp:Label ID="DescriptionLabel" runat="server" 
                                Text=''<%# Eval("Description") %>'' />
                        </td>
                    </tr>
                </ItemTemplate>
                <LayoutTemplate>
                    <div ><table id="thetable" width="97%" cellpadding="0px" cellspacing="0px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;">
                        <thead>
                            <tr style="background-color:#C6D7B5;">
                                <th style="border-removed2px solid #003366; ">...</th>
                                <th style="border-removed2px solid #003366; ">Title</th>
                                <th style="border-removed2px solid #003366; ">Description</th>
                            </tr>
                       </thead>
                       <tbody><tr id="itemPlaceholder"  runat="server"></tr></tbody>
                    </table></div>
                </LayoutTemplate>
                <SelectedItemTemplate>
                    <tr style="">
                        <td>
                            <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" />

                            <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />
                        </td>
                        <%--<td>
                            <asp:Label ID="QuizIDLabel" runat="server" 
                                Text=''<%# Eval("QuizID") %>'' />
                        </td>--%>
                        <td>
                            <asp:Label ID="TitleLabel" runat="server" Text=''<%# Eval("Title") %>'' />
                        </td>
                        <td>
                            <asp:Label ID="DescriptionLabel" runat="server" 
                                Text=''<%# Eval("Description") %>'' />
                        </td>
                    </tr>
                </SelectedItemTemplate>
            </asp:ListView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:QuizSysDBConnectionString %>" 
                
                SelectCommand="SELECT * FROM [Quiz]" 
                DeleteCommand="DELETE FROM [Quiz] WHERE [QuizID] = @QuizID" 
                InsertCommand="INSERT INTO [Quiz] ([Title], [Description]) VALUES (@Title, @Description)" 
                
                
                UpdateCommand="UPDATE [Quiz] SET [Title] = @Title, [Description] = @Description WHERE [QuizID] = @QuizID">
                <DeleteParameters>
                    <asp:Parameter Name="QuizID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="QuizID" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>
    </div>

    <br /><br />

    <%--Second ListView that will contain the content of the quiz--%>
    <div align="center">
        <asp:ListView ID="ListView2" runat="server" DataSourceID="SqlDataSource2" 
            DataKeyNames="QuestionID" InsertItemPosition="LastItem">
            
            <EditItemTemplate>

                <tr style="">
                    <td>
                        <asp:ImageButton ID="UpdateButton" ImageUrl="Images/icons/update24.png" ToolTip="Update" runat="server" CommandName="Update" />
                            
                        <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/cancel324.png" ToolTip="Cancel" runat="server" CommandName="Cancel" />
                    </td>
                    <%--<td>
                        <asp:Label ID="QuestionIDLabel1" runat="server" 
                            Text=''<%# Eval("QuestionID") %>'' />
                    </td>--%>
                    <td>
                        <asp:TextBox ID="QuestionTextBox" runat="server" 
                            Text=''<%# Bind("Question") %>'' />
                    </td>
                    <td>
                        <asp:TextBox ID="QuestionOrderTextBox" runat="server" 
                            Text=''<%# Bind("QuestionOrder") %>'' />
                    </td>
                    <td>
                        <asp:TextBox ID="AnswerExplanationTextBox" runat="server" 
                            Text=''<%# Bind("AnswerExplanation") %>'' />
                    </td>
                </tr>
            </EditItemTemplate>

            <EmptyDataTemplate>
                <table  runat="server" 
                    style="">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>

            <InsertItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="InsertButton" ImageUrl="Images/icons/add24.png" ToolTip="Add" runat="server" CommandName="Insert" />
                        
                        <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/clear24.png" ToolTip="Cancel"  runat="server" CommandName="Cancel" />
                    </td>
                    <%--<td>
                         </td>--%>
                    <td>
                        <asp:TextBox ID="QuestionTextBox" runat="server" 
                            Text=''<%# Bind("Question") %>'' />
                    </td>
                    <td>
                        <asp:TextBox ID="QuestionOrderTextBox" runat="server" 
                            Text=''<%# Bind("QuestionOrder") %>''/>
                    </td>
                    <td>
                        <asp:TextBox ID="AnswerExplanationTextBox" runat="server" 
                            Text=''<%# Bind("AnswerExplanation") %>'' />
                    </td>
                </tr>

            </InsertItemTemplate>

            <ItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="delete" runat="server" CommandName="Delete" />

                        <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />

                        <asp:ImageButton ID="SelectButton" ImageUrl="Images/icons/select.png" ToolTip="Select" runat="server" CommandName="Select" />
                            <%--<asp:Button ID="SelectButton" runat="server" CommandName="Select" Text="Select" />--%>
                    </td>
                    <td>
                        <asp:Label ID="QuestionLabel" runat="server" Text=''<%# Eval("Question") %>'' />
                    </td>
                    <td>
                        <asp:Label ID="QuestionOrderLabel" runat="server" 
                            Text=''<%# Eval("QuestionOrder") %>'' />
                    </td>
                    <td>
                        <asp:Label ID="AnswerExplanationLabel" runat="server" 
                            Text=''<%# Eval("AnswerExplanation") %>'' />
                    </td>
                </tr>
            </ItemTemplate>

            <LayoutTemplate>
                <div ><table id="thetable" width="97%" cellpadding="0px" cellspacing="0px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;">
                        <thead>
                            <tr style="background-color:#C6D7B5;">
                                <th style="border-removed2px solid #003366; ">...</th>
                                <th style="border-removed2px solid #003366; ">Question</th>
                                <th style="border-removed2px solid #003366; ">Question Order</th>
                                <th style="border-removed2px solid #003366; ">Answer Explanation</th>
                            </tr>
                       </thead>
                       <tbody><tr id="itemPlaceholder"  runat="server"></tr></tbody>
                    </table></div>     
            </LayoutTemplate>
            <SelectedItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" />

                        <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="QuestionLabel" runat="server" Text=''<%# Eval("Question") %>'' />
                    </td>
                    <td>
                        <asp:Label ID="QuestionOrderLabel" runat="server" 
                            Text=''<%# Eval("QuestionOrder") %>'' />
                    </td>
                    <td>
                        <asp:Label ID="AnswerExplanationLabel" runat="server" 
                            Text=''<%# Eval("AnswerExplanation") %>'' />
                    </td>
                </tr>
            </SelectedItemTemplate>
        </asp:ListView>
        </div>

        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:QuizSysDBConnectionString %>" 
            SelectCommand="SELECT [Question].* FROM [Question] INNER JOIN [QuizContent] ON [QuizContent].[QuizID] = @QuizID"

            DeleteCommand="DELETE FROM [Question] WHERE [QuestionID] = @QuestionID" 
            InsertCommand="INSERT INTO [Question] ([Question], [QuestionOrder], [AnswerExplanation]) VALUES (@Question, @QuestionOrder, @AnswerExplanation)" 
                
                
            UpdateCommand="UPDATE [Question] SET [Question] = @Question, [QuestionOrder] = @QuestionOrder, [AnswerExplanation] = @AnswerExplanation WHERE [QuestionID] = @QuestionID">

                <DeleteParameters>
                    <asp:Parameter Name="QuestionID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="Question" Type="String" />
                    <asp:Parameter Name="QuestionOrder" Type="Int32" />
                    <asp:Parameter Name="AnswerExplanation" Type="String" />
                    <asp:ControlParameter ControlID="ListView1" Name="QuizID" PropertyName="SelectedValue" Type="Int32" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Question" Type="String" />
                    <asp:Parameter Name="QuestionOrder" Type="Int32" />
                    <asp:Parameter Name="AnswerExplanation" Type="String" />
                </UpdateParameters>

            <SelectParameters>
                <asp:ControlParameter ControlID="ListView1" Name="QuizID" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>

        <br /><br />

    <%--Third ListView that will contain the content of the quiz--%>
    <div align="center">
        <asp:ListView ID="ListView3" runat="server" DataSourceID="SqlDataSource3" 
            DataKeyNames="AnswerID" InsertItemPosition="LastItem">
            
            <EditItemTemplate>

                <tr style="">
                    <td>
                        <asp:ImageButton ID="UpdateButton" ImageUrl="Images/icons/update24.png" ToolTip="Update" runat="server" CommandName="Update" />
                            
                        <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/cancel324.png" ToolTip="Cancel" runat="server" CommandName="Cancel" />
                    </td>
                    <%--<td>
                        <asp:Label ID="AnswerIDLabel1" runat="server" Text=''<%# Eval("AnswerID") %>'' />
                    </td>--%>
                    <td>
                        <asp:TextBox ID="AnswerTextBox" runat="server" 
                            Text=''<%# Bind("Answer") %>'' />
                    </td>
                </tr>
            </EditItemTemplate>

            <EmptyDataTemplate>
                <table  runat="server" 
                    style="">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>

            <InsertItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="InsertButton" ImageUrl="Images/icons/add24.png" ToolTip="Add" runat="server" CommandName="Insert" />
                        
                        <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/clear24.png" ToolTip="Cancel" runat="server" CommandName="Cancel" />
                    </td>
                    <%--<td>
                         </td>--%>
                    <td>
                        <asp:TextBox ID="AnswerTextBox" runat="server" 
                            Text=''<%# Bind("Answer") %>''/>
                    </td>
                </tr>

            </InsertItemTemplate>

            <ItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" />

                        <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />
                    </td>
                    <%--<td>
                        <asp:Label ID="AnswerIDLabel" runat="server" Text=''<%# Eval("AnswerID") %>'' />
                    </td>--%>
                    <td>
                        <asp:Label ID="AnswerLabel" runat="server" Text=''<%# Eval("Answer") %>'' />
                    </td>
                </tr>
            </ItemTemplate>

            <LayoutTemplate>
                <div ><table id="thetable" width="97%" cellpadding="0px" cellspacing="0px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;">
                    <thead>
                        <tr style="background-color:#C6D7B5;">
                            <th style="border-removed2px solid #003366; ">...</th>
                            <th style="border-removed2px solid #003366; ">Answer</th>
                        </tr>
                    </thead>
                    <tbody><tr id="itemPlaceholder"  runat="server"></tr></tbody>
                </table></div>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" />

                        <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="AnswerLabel" runat="server" 
                            Text=''<%# Eval("Answer") %>'' />
                    </td>
                </tr>
            </SelectedItemTemplate>
        </asp:ListView>
        </div>

        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:QuizSysDBConnectionString %>" 
            SelectCommand="SELECT [Answers].* FROM [Answers] INNER JOIN [QuizContent] ON [QuizContent].QuestionID = @QuestionID"

            DeleteCommand="DELETE FROM [Answers] WHERE [AnswerID] = @AnswerID" 
            InsertCommand="INSERT INTO [Answers] ([Answer]) VALUES (@Answer)" 
                
                
            UpdateCommand="UPDATE [Answers] SET [Answer] = @Answer WHERE [AnswerID] = @AnswerID">
                <DeleteParameters>
                    <asp:Parameter Name="AnswerID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="Answer" Type="String" />
                    <asp:ControlParameter ControlID="ListView2" Name="QuestionID" PropertyName="SelectedValue" Type="Int32" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Answer" Type="String" />
                </UpdateParameters>

            <SelectParameters>
                <asp:ControlParameter ControlID="ListView2" Name="QuestionID" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>



**注意:**
我没有任何代码隐藏.问题再次如下:运行代码时,我将看到三个ListView控件.它应该只显示其中之一.并且,当用户选择其中一个行时,将显示第二个ListView,以此类推.对于第三个ListView,依此类推. SelectCommand ="SELECT * FROM [测验]" DeleteCommand =从[测验]中删除[测验ID] = @测验ID" InsertCommand ="INSERT INTO [测验]([标题],[描述])值(@Title,@Description)" UpdateCommand ="UPDATE [Quiz] SET [Title] = @Title,[Description] = @Description WHERE [QuizID] = @QuizID"> < DeleteParameters> < asp:参数名称="QuizID"类型="Int32"/> </DeleteParameters> < InsertParameters> < asp:参数名称=标题" Type ="String"/> < asp:参数名称=描述" Type =字符串"/> </InsertParameters> < UpdateParameters> < asp:参数名称=标题" Type ="String"/> < asp:参数名称=描述" Type =字符串"/> < asp:参数名称="QuizID"类型="Int32"/> </UpdateParameters> </asp:SqlDataSource> </div> < br/>< br/> <%-包含测验内容的第二个ListView-%> < div align ="center"> < asp:ListView ID ="ListView2" runat =服务器" DataSourceID ="SqlDataSource2" DataKeyNames ="QuestionID" InsertItemPosition ="LastItem"> < EditItemTemplate> < tr style ="> < td> < asp:ImageButton ID ="UpdateButton" ImageUrl ="Images/icons/update24.png" ToolTip ="Update" runat ="server" CommandName ="Update"/> < asp:ImageButton ID ="CancelButton" ImageUrl ="Images/icons/cancel324.png" ToolTip ="Cancel" runat ="server" CommandName ="Cancel"/> </td> <%-< td> < asp:Label ID ="QuestionIDLabel1" runat ="server" Text =''<%#Eval("QuestionID")%>''/> </td>-%> < td> < asp:TextBox ID ="QuestionTextBox" runat =服务器" Text =''<%#Bind("Question")%>''/> </td> < td> < asp:TextBox ID ="QuestionOrderTextBox" runat =服务器" Text =''<%#Bind("QuestionOrder")%>''/> </td> < td> < asp:TextBox ID ="AnswerExplanationTextBox" runat =服务器" Text =''<%#Bind("AnswerExplanation")%>''/> </td> </tr> </EditItemTemplate> < EmptyDataTemplate> < table runat ="server" style ="> < tr> < td> 没有数据返回. </tr> </table> </EmptyDataTemplate> < InsertItemTemplate> < tr style ="> < td> < asp:ImageButton ID ="InsertButton" ImageUrl ="Images/icons/add24.png" ToolTip ="Add" runat ="server" CommandName ="Insert"/> < asp:ImageButton ID ="CancelButton" ImageUrl ="Images/icons/clear24.png" ToolTip ="Cancel" runat ="server" CommandName ="Cancel"/> </td> <%-< td> </td>-%> < td> < asp:TextBox ID ="QuestionTextBox" runat =服务器" Text =''<%#Bind("Question")%>''/> </td> < td> < asp:TextBox ID ="QuestionOrderTextBox" runat =服务器" Text =''<%#Bind("QuestionOrder")%>''/> </td> < td> < asp:TextBox ID ="AnswerExplanationTextBox" runat =服务器" Text =''<%#Bind("AnswerExplanation")%>''/> </td> </tr> </InsertItemTemplate> < ItemTemplate> < tr style ="> < td> < asp:ImageButton ID ="DeleteButton" ImageUrl ="Images/icons/delete24.png" ToolTip ="delete" runat ="server" CommandName ="Delete"/> < asp:ImageButton ID ="EditButton" ImageUrl ="Images/icons/edit24.png" ToolTip ="Edit" runat ="server" CommandName ="Edit"/> < asp:ImageButton ID ="SelectButton" ImageUrl ="Images/icons/select.png" ToolTip ="Select" runat ="server" CommandName ="Select"/> <%-< asp:Button ID ="SelectButton" runat ="server" CommandName ="Select" Text ="Select"/>-%> </td> < td> < asp:Label ID ="QuestionLabel" runat ="server" Text =''<%#Eval("Question")%>''/> </td> < td> < asp:Label ID ="QuestionOrderLabel" runat ="server" Text =''<%#Eval("QuestionOrder")%>''/> </td> < td> < asp:Label ID ="AnswerExplanationLabel" runat ="server" Text =''<%#Eval("AnswerExplanation")%>''/> </td> </tr> </ItemTemplate> < LayoutTemplate> < div><表格ID ="thetable" width ="97%" cellpadding ="0px" cellspacing ="0px" style ="margin:0px 0px 0px 0px; border:2px solid#003366; font-size: 13px; font-weight:bold;> < thead> < tr style ="background-color:#C6D7B5;"> < th style ="border-removed2px solid#003366;"> ...&th;/th; < th style ="border-removed2px solid#003366;">问题</th> < th style ="border-removed2px solid#003366;">问题单</th> < th style ="border-removed2px solid#003366;">答案说明</th> </tr> </thead> < tbody>< tr id ="itemPlaceholder" runat ="server"></tr></tbody> </table></div> </LayoutTemplate> < SelectedItemTemplate> < tr style ="> < td> < asp:ImageButton ID ="DeleteButton" ImageUrl ="Images/icons/delete24.png" ToolTip ="Delete" runat ="server" CommandName ="Delete"/> < asp:ImageButton ID ="EditButton" ImageUrl ="Images/icons/edit24.png" ToolTip ="Edit" runat ="server" CommandName ="Edit"/> </td> < td> < asp:Label ID ="QuestionLabel" runat ="server" Text =''<%#Eval("Question")%>''/> </td> < td> < asp:Label ID ="QuestionOrderLabel" runat ="server" Text =''<%#Eval("QuestionOrder")%>''/> </td> < td> < asp:Label ID ="AnswerExplanationLabel" runat ="server" Text =''<%#Eval("AnswerExplanation")%>''/> </td> </tr> </SelectedItemTemplate> </asp:ListView> </div> < asp:SqlDataSource ID ="SqlDataSource2" runat =服务器" ConnectionString =<%


ConnectionStrings:QuizSysDBConnectionString%>" SelectCommand ="SELECT [问题].*从[问题]内部联接[QuizContent]开启[QuizContent].[QuizID] = @QuizID" DeleteCommand ="DELETE FROM [Question] WHERE [QuestionID] = @QuestionID" InsertCommand ="INSERT INTO [问题]([问题],[QuestionOrder],[AnswerExplanation])值(@Question,@QuestionOrder,@AnswerExplanation)" UpdateCommand ="UPDATE [问题] SET [问题] = @问题,[QuestionOrder] = @QuestionOrder,[AnswerExplanation] = @AnswerExplanation,其中[QuestionID] = @QuestionID"> < DeleteParameters> < asp:参数名称="QuestionID"类型="Int32"/> </DeleteParameters> < InsertParameters> < asp:参数名称=问题"类型=字符串"/> < asp:参数名称="QuestionOrder"类型="Int32"/> < asp:参数名称="AnswerExplanation" Type ="String"/> < asp:ControlParameter ControlID ="ListView1" Name ="QuizID" PropertyName ="SelectedValue" Type ="Int32"/> </InsertParameters> < UpdateParameters> < asp:参数名=问题" Type =字符串"/> < asp:参数名称="QuestionOrder"类型="Int32"/> < asp:参数名称="AnswerExplanation" Type ="String"/> </UpdateParameters> < SelectParameters> < asp:ControlParameter ControlID ="ListView1" Name ="QuizID" PropertyName ="SelectedValue" Type ="Int32"/> </SelectParameters> </asp:SqlDataSource> < br/>< br/> <%-包含测验内容的第三ListView-%> < div align ="center"> < asp:ListView ID ="ListView3" runat =服务器" DataSourceID ="SqlDataSource3" DataKeyNames ="AnswerID" InsertItemPosition ="LastItem"> < EditItemTemplate> < tr style ="> < td> < asp:ImageButton ID ="UpdateButton" ImageUrl ="Images/icons/update24.png" ToolTip ="Update" runat ="server" CommandName ="Update"/> < asp:ImageButton ID ="CancelButton" ImageUrl ="Images/icons/cancel324.png" ToolTip ="Cancel" runat ="server" CommandName ="Cancel"/> </td> <%-< td> < asp:Label ID ="AnswerIDLabel1" runat ="server" Text =''<%#Eval("AnswerID")%>''/> </td>-%> < td> < asp:TextBox ID ="AnswerTextBox" runat =服务器" Text =''<%#Bind("Answer")%>''/> </td> </tr> </EditItemTemplate> < EmptyDataTemplate> < table runat ="server" style ="> < tr> < td> 没有数据返回. </tr> </table> </EmptyDataTemplate> < InsertItemTemplate> < tr style ="> < td> < asp:ImageButton ID ="InsertButton" ImageUrl ="Images/icons/add24.png" ToolTip ="Add" runat ="server" CommandName ="Insert"/> < asp:ImageButton ID ="CancelButton" ImageUrl ="Images/icons/clear24.png" ToolTip ="Cancel" runat ="server" CommandName ="Cancel"/> </td> <%-< td> </td>-%> < td> < asp:TextBox ID ="AnswerTextBox" runat =服务器" Text =''<%#Bind("Answer")%>''/> </td> </tr> </InsertItemTemplate> < ItemTemplate> < tr style ="> < td> < asp:ImageButton ID ="DeleteButton" ImageUrl ="Images/icons/delete24.png" ToolTip ="Delete" runat ="server" CommandName ="Delete"/> < asp:ImageButton ID ="EditButton" ImageUrl ="Images/icons/edit24.png" ToolTip ="Edit" runat ="server" CommandName ="Edit"/> </td> <%-< td> < asp:Label ID ="AnswerIDLabel" runat ="server" Text =''<%#Eval("AnswerID")%>''/> </td>-%> < td> < asp:Label ID ="AnswerLabel" runat ="server" Text =''<%#Eval("Answer")%>''/> </td> </tr> </ItemTemplate> < LayoutTemplate> < div><表格ID ="thetable" width ="97%" cellpadding ="0px" cellspacing ="0px" style ="margin:0px 0px 0px 0px; border:2px solid#003366; font-size: 13px; font-weight:bold;> < thead> < tr style ="background-color:#C6D7B5;"> < th style ="border-removed2px solid#003366;"> ...&th;/th; < th style ="border-removed2px实体#003366;">答案</th> </tr> </thead> < tbody>< tr id ="itemPlaceholder" runat ="server"></tr></tbody> </table></div> </LayoutTemplate> < SelectedItemTemplate> < tr style ="> < td> < asp:ImageButton ID ="DeleteButton" ImageUrl ="Images/icons/delete24.png" ToolTip ="Delete" runat ="server" CommandName ="Delete"/> < asp:ImageButton ID ="EditButton" ImageUrl ="Images/icons/edit24.png" ToolTip ="Edit" runat ="server" CommandName ="Edit"/> </td> < td> < asp:标签ID ="AnswerLabel" runat =服务器" Text =''<%#Eval("Answer")%>''/> </td> </tr> </SelectedItemTemplate> </asp:ListView> </div> < asp:SqlDataSource ID ="SqlDataSource3" runat =服务器" ConnectionString =<%


ConnectionStrings:QuizSysDBConnectionString%>" SelectCommand ="SELECT [答案].*从[答案]内联接[QuizContent]开启[QuizContent] .QuestionID = @QuestionID" DeleteCommand ="DELETE FROM [Answers] WHERE [AnswerID] = @AnswerID" InsertCommand ="INSERT INTO [答案]([答案])值(@Answer)" UpdateCommand ="UPDATE [Answers] SET [Answer] = @Answer WHERE [AnswerID] = @AnswerID"> < DeleteParameters> < asp:参数名称="AnswerID"类型="Int32"/> </DeleteParameters> < InsertParameters> < asp:参数名称=答案" Type ="String"/> < asp:ControlParameter ControlID ="ListView2" Name ="QuestionID" PropertyName ="SelectedValue" Type ="Int32"/> </InsertParameters> < UpdateParameters> < asp:参数名称=答案" Type ="String"/> </UpdateParameters> < SelectParameters> < asp:ControlParameter ControlID ="ListView2" Name ="QuestionID" PropertyName ="SelectedValue" Type ="Int32"/> </SelectParameters> </asp:SqlDataSource>



**注意:**
我没有任何代码隐藏.问题再次如下:运行代码时,我将看到三个ListView控件.它应该只显示其中之一.然后,当用户选择其中一个行时,将显示第二个ListView,依此类推.对于第三个ListView,依此类推.


I am a new ASP.NET developer and I have to create a quiz engine application. I am using three LiveView controls to show:
1. quiz information
2. question information (based on the selected quiz on the first ListView)
3. answers information (based on the selected question on the second ListView)

I have the following database design:

QuizContent Table: ID, QuizID, QuestionID, AnswerID
Quiz Table: QuizID, Title, Description
Question Table: QuestionID, Question, QuestionOrder, AnswerExplanation
Answers Table: AnswerID, Answer



What I want now is the following: when the user (who is the Admin) comes to the Quiz Engine Page, he should only see the first ListView which is mainly about the Quiz Information. And when he selects one of the quizzes, the second ListView will be displayed with the Question information of that selected quiz. And when he selects one of the questions, the third ListView will be displayed with the answers information of that selected question.

**So how to do that?**

I know I should not post too much code or information, but I have to do it to make it clear:

<asp:ListView ID="ListView1" runat="server" DataKeyNames="QuizID" 
                DataSourceID="SqlDataSource1" InsertItemPosition="LastItem" >
                
                <EditItemTemplate>
                    <tr style="">
                        <td>
                            <asp:ImageButton ID="UpdateButton" ImageUrl="Images/icons/update24.png" ToolTip="Update"  runat="server" CommandName="Update" />
                            
                            <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/cancel324.png" ToolTip="Cancel" runat="server" CommandName="Cancel" />
                        </td>
                        <td>
                            <asp:TextBox ID="TitleTextBox" runat="server" Text=''<%# Bind("Title") %>'' />
                        </td>
                        <td>
                            <asp:TextBox ID="DescriptionTextBox" runat="server" 
                                Text=''<%# Bind("Description") %>'' />
                        </td>
                    </tr>
                </EditItemTemplate>
                <EmptyDataTemplate>
                    <table id="Table1"  runat="server" style="">
                        <tr>
                            <td>
                                No data was returned.</td>
                        </tr>
                    </table>
                </EmptyDataTemplate>
                <InsertItemTemplate>
                    <tr style="">
                        <td>
                            <asp:ImageButton ID="InsertButton" ImageUrl="Images/icons/add24.png" ToolTip="Add"  runat="server" CommandName="Insert" />
                        
                            <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/clear24.png" ToolTip="Cancel"  runat="server" CommandName="Cancel" />
                        </td>

                        <%--<td>
                             </td>--%>
                        <td>
                            <asp:TextBox ID="TitleTextBox" runat="server" Text=''<%# Bind("Title") %>'' />
                        </td>
                        <td>
                            <asp:TextBox ID="DescriptionTextBox" runat="server" 
                                Text=''<%# Bind("Description") %>'' />
                        </td>
                    </tr>
                </InsertItemTemplate>
                <ItemTemplate>
                    <tr style="">
                        <td>
                            <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete"  runat="server" CommandName="Delete" />

                            <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit"  runat="server" CommandName="Edit" />

                            <asp:ImageButton ID="SelectButton" ImageUrl="Images/icons/select.png" ToolTip="Select"  runat="server" CommandName="Select" />
                            <%--<asp:Button ID="SelectButton" runat="server" CommandName="Select" Text="Select" />--%>
                        </td>
                        <%--<td>
                            <asp:Label ID="QuizIDLabel" runat="server" 
                                Text=''<%# Eval("QuizID") %>'' />
                        </td>--%>
                        <td>
                            <asp:Label ID="TitleLabel" runat="server" Text=''<%# Eval("Title") %>'' />
                        </td>
                        <td>
                            <asp:Label ID="DescriptionLabel" runat="server" 
                                Text=''<%# Eval("Description") %>'' />
                        </td>
                    </tr>
                </ItemTemplate>
                <LayoutTemplate>
                    <div ><table id="thetable" width="97%" cellpadding="0px" cellspacing="0px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;">
                        <thead>
                            <tr style="background-color:#C6D7B5;">
                                <th style="border-removed2px solid #003366; ">...</th>
                                <th style="border-removed2px solid #003366; ">Title</th>
                                <th style="border-removed2px solid #003366; ">Description</th>
                            </tr>
                       </thead>
                       <tbody><tr id="itemPlaceholder"  runat="server"></tr></tbody>
                    </table></div>
                </LayoutTemplate>
                <SelectedItemTemplate>
                    <tr style="">
                        <td>
                            <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" />

                            <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />
                        </td>
                        <%--<td>
                            <asp:Label ID="QuizIDLabel" runat="server" 
                                Text=''<%# Eval("QuizID") %>'' />
                        </td>--%>
                        <td>
                            <asp:Label ID="TitleLabel" runat="server" Text=''<%# Eval("Title") %>'' />
                        </td>
                        <td>
                            <asp:Label ID="DescriptionLabel" runat="server" 
                                Text=''<%# Eval("Description") %>'' />
                        </td>
                    </tr>
                </SelectedItemTemplate>
            </asp:ListView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:QuizSysDBConnectionString %>" 
                
                SelectCommand="SELECT * FROM [Quiz]" 
                DeleteCommand="DELETE FROM [Quiz] WHERE [QuizID] = @QuizID" 
                InsertCommand="INSERT INTO [Quiz] ([Title], [Description]) VALUES (@Title, @Description)" 
                
                
                UpdateCommand="UPDATE [Quiz] SET [Title] = @Title, [Description] = @Description WHERE [QuizID] = @QuizID">
                <DeleteParameters>
                    <asp:Parameter Name="QuizID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Title" Type="String" />
                    <asp:Parameter Name="Description" Type="String" />
                    <asp:Parameter Name="QuizID" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>
    </div>

    <br /><br />

    <%--Second ListView that will contain the content of the quiz--%>
    <div align="center">
        <asp:ListView ID="ListView2" runat="server" DataSourceID="SqlDataSource2" 
            DataKeyNames="QuestionID" InsertItemPosition="LastItem">
            
            <EditItemTemplate>

                <tr style="">
                    <td>
                        <asp:ImageButton ID="UpdateButton" ImageUrl="Images/icons/update24.png" ToolTip="Update" runat="server" CommandName="Update" />
                            
                        <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/cancel324.png" ToolTip="Cancel" runat="server" CommandName="Cancel" />
                    </td>
                    <%--<td>
                        <asp:Label ID="QuestionIDLabel1" runat="server" 
                            Text=''<%# Eval("QuestionID") %>'' />
                    </td>--%>
                    <td>
                        <asp:TextBox ID="QuestionTextBox" runat="server" 
                            Text=''<%# Bind("Question") %>'' />
                    </td>
                    <td>
                        <asp:TextBox ID="QuestionOrderTextBox" runat="server" 
                            Text=''<%# Bind("QuestionOrder") %>'' />
                    </td>
                    <td>
                        <asp:TextBox ID="AnswerExplanationTextBox" runat="server" 
                            Text=''<%# Bind("AnswerExplanation") %>'' />
                    </td>
                </tr>
            </EditItemTemplate>

            <EmptyDataTemplate>
                <table  runat="server" 
                    style="">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>

            <InsertItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="InsertButton" ImageUrl="Images/icons/add24.png" ToolTip="Add" runat="server" CommandName="Insert" />
                        
                        <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/clear24.png" ToolTip="Cancel"  runat="server" CommandName="Cancel" />
                    </td>
                    <%--<td>
                         </td>--%>
                    <td>
                        <asp:TextBox ID="QuestionTextBox" runat="server" 
                            Text=''<%# Bind("Question") %>'' />
                    </td>
                    <td>
                        <asp:TextBox ID="QuestionOrderTextBox" runat="server" 
                            Text=''<%# Bind("QuestionOrder") %>''/>
                    </td>
                    <td>
                        <asp:TextBox ID="AnswerExplanationTextBox" runat="server" 
                            Text=''<%# Bind("AnswerExplanation") %>'' />
                    </td>
                </tr>

            </InsertItemTemplate>

            <ItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="delete" runat="server" CommandName="Delete" />

                        <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />

                        <asp:ImageButton ID="SelectButton" ImageUrl="Images/icons/select.png" ToolTip="Select" runat="server" CommandName="Select" />
                            <%--<asp:Button ID="SelectButton" runat="server" CommandName="Select" Text="Select" />--%>
                    </td>
                    <td>
                        <asp:Label ID="QuestionLabel" runat="server" Text=''<%# Eval("Question") %>'' />
                    </td>
                    <td>
                        <asp:Label ID="QuestionOrderLabel" runat="server" 
                            Text=''<%# Eval("QuestionOrder") %>'' />
                    </td>
                    <td>
                        <asp:Label ID="AnswerExplanationLabel" runat="server" 
                            Text=''<%# Eval("AnswerExplanation") %>'' />
                    </td>
                </tr>
            </ItemTemplate>

            <LayoutTemplate>
                <div ><table id="thetable" width="97%" cellpadding="0px" cellspacing="0px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;">
                        <thead>
                            <tr style="background-color:#C6D7B5;">
                                <th style="border-removed2px solid #003366; ">...</th>
                                <th style="border-removed2px solid #003366; ">Question</th>
                                <th style="border-removed2px solid #003366; ">Question Order</th>
                                <th style="border-removed2px solid #003366; ">Answer Explanation</th>
                            </tr>
                       </thead>
                       <tbody><tr id="itemPlaceholder"  runat="server"></tr></tbody>
                    </table></div>     
            </LayoutTemplate>
            <SelectedItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" />

                        <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="QuestionLabel" runat="server" Text=''<%# Eval("Question") %>'' />
                    </td>
                    <td>
                        <asp:Label ID="QuestionOrderLabel" runat="server" 
                            Text=''<%# Eval("QuestionOrder") %>'' />
                    </td>
                    <td>
                        <asp:Label ID="AnswerExplanationLabel" runat="server" 
                            Text=''<%# Eval("AnswerExplanation") %>'' />
                    </td>
                </tr>
            </SelectedItemTemplate>
        </asp:ListView>
        </div>

        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:QuizSysDBConnectionString %>" 
            SelectCommand="SELECT [Question].* FROM [Question] INNER JOIN [QuizContent] ON [QuizContent].[QuizID] = @QuizID"

            DeleteCommand="DELETE FROM [Question] WHERE [QuestionID] = @QuestionID" 
            InsertCommand="INSERT INTO [Question] ([Question], [QuestionOrder], [AnswerExplanation]) VALUES (@Question, @QuestionOrder, @AnswerExplanation)" 
                
                
            UpdateCommand="UPDATE [Question] SET [Question] = @Question, [QuestionOrder] = @QuestionOrder, [AnswerExplanation] = @AnswerExplanation WHERE [QuestionID] = @QuestionID">

                <DeleteParameters>
                    <asp:Parameter Name="QuestionID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="Question" Type="String" />
                    <asp:Parameter Name="QuestionOrder" Type="Int32" />
                    <asp:Parameter Name="AnswerExplanation" Type="String" />
                    <asp:ControlParameter ControlID="ListView1" Name="QuizID" PropertyName="SelectedValue" Type="Int32" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Question" Type="String" />
                    <asp:Parameter Name="QuestionOrder" Type="Int32" />
                    <asp:Parameter Name="AnswerExplanation" Type="String" />
                </UpdateParameters>

            <SelectParameters>
                <asp:ControlParameter ControlID="ListView1" Name="QuizID" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>

        <br /><br />

    <%--Third ListView that will contain the content of the quiz--%>
    <div align="center">
        <asp:ListView ID="ListView3" runat="server" DataSourceID="SqlDataSource3" 
            DataKeyNames="AnswerID" InsertItemPosition="LastItem">
            
            <EditItemTemplate>

                <tr style="">
                    <td>
                        <asp:ImageButton ID="UpdateButton" ImageUrl="Images/icons/update24.png" ToolTip="Update" runat="server" CommandName="Update" />
                            
                        <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/cancel324.png" ToolTip="Cancel" runat="server" CommandName="Cancel" />
                    </td>
                    <%--<td>
                        <asp:Label ID="AnswerIDLabel1" runat="server" Text=''<%# Eval("AnswerID") %>'' />
                    </td>--%>
                    <td>
                        <asp:TextBox ID="AnswerTextBox" runat="server" 
                            Text=''<%# Bind("Answer") %>'' />
                    </td>
                </tr>
            </EditItemTemplate>

            <EmptyDataTemplate>
                <table  runat="server" 
                    style="">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>

            <InsertItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="InsertButton" ImageUrl="Images/icons/add24.png" ToolTip="Add" runat="server" CommandName="Insert" />
                        
                        <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/clear24.png" ToolTip="Cancel" runat="server" CommandName="Cancel" />
                    </td>
                    <%--<td>
                         </td>--%>
                    <td>
                        <asp:TextBox ID="AnswerTextBox" runat="server" 
                            Text=''<%# Bind("Answer") %>''/>
                    </td>
                </tr>

            </InsertItemTemplate>

            <ItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" />

                        <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />
                    </td>
                    <%--<td>
                        <asp:Label ID="AnswerIDLabel" runat="server" Text=''<%# Eval("AnswerID") %>'' />
                    </td>--%>
                    <td>
                        <asp:Label ID="AnswerLabel" runat="server" Text=''<%# Eval("Answer") %>'' />
                    </td>
                </tr>
            </ItemTemplate>

            <LayoutTemplate>
                <div ><table id="thetable" width="97%" cellpadding="0px" cellspacing="0px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;">
                    <thead>
                        <tr style="background-color:#C6D7B5;">
                            <th style="border-removed2px solid #003366; ">...</th>
                            <th style="border-removed2px solid #003366; ">Answer</th>
                        </tr>
                    </thead>
                    <tbody><tr id="itemPlaceholder"  runat="server"></tr></tbody>
                </table></div>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <tr style="">
                    <td>
                        <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" />

                        <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="AnswerLabel" runat="server" 
                            Text=''<%# Eval("Answer") %>'' />
                    </td>
                </tr>
            </SelectedItemTemplate>
        </asp:ListView>
        </div>

        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:QuizSysDBConnectionString %>" 
            SelectCommand="SELECT [Answers].* FROM [Answers] INNER JOIN [QuizContent] ON [QuizContent].QuestionID = @QuestionID"

            DeleteCommand="DELETE FROM [Answers] WHERE [AnswerID] = @AnswerID" 
            InsertCommand="INSERT INTO [Answers] ([Answer]) VALUES (@Answer)" 
                
                
            UpdateCommand="UPDATE [Answers] SET [Answer] = @Answer WHERE [AnswerID] = @AnswerID">
                <DeleteParameters>
                    <asp:Parameter Name="AnswerID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="Answer" Type="String" />
                    <asp:ControlParameter ControlID="ListView2" Name="QuestionID" PropertyName="SelectedValue" Type="Int32" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Answer" Type="String" />
                </UpdateParameters>

            <SelectParameters>
                <asp:ControlParameter ControlID="ListView2" Name="QuestionID" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>



**NOTE:**
I don''t have any code-behind. And again the problem is as following: when I run the code, I will see the three ListView controls. It should show only one of them. And when the user selects one of the rows, the second ListView will be displayed and so on for the third ListView.

解决方案

ConnectionStrings:QuizSysDBConnectionString %>" SelectCommand="SELECT * FROM [Quiz]" DeleteCommand="DELETE FROM [Quiz] WHERE [QuizID] = @QuizID" InsertCommand="INSERT INTO [Quiz] ([Title], [Description]) VALUES (@Title, @Description)" UpdateCommand="UPDATE [Quiz] SET [Title] = @Title, [Description] = @Description WHERE [QuizID] = @QuizID"> <DeleteParameters> <asp:Parameter Name="QuizID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Description" Type="String" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Description" Type="String" /> <asp:Parameter Name="QuizID" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource> </div> <br /><br /> <%--Second ListView that will contain the content of the quiz--%> <div align="center"> <asp:ListView ID="ListView2" runat="server" DataSourceID="SqlDataSource2" DataKeyNames="QuestionID" InsertItemPosition="LastItem"> <EditItemTemplate> <tr style=""> <td> <asp:ImageButton ID="UpdateButton" ImageUrl="Images/icons/update24.png" ToolTip="Update" runat="server" CommandName="Update" /> <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/cancel324.png" ToolTip="Cancel" runat="server" CommandName="Cancel" /> </td> <%--<td> <asp:Label ID="QuestionIDLabel1" runat="server" Text=''<%# Eval("QuestionID") %>'' /> </td>--%> <td> <asp:TextBox ID="QuestionTextBox" runat="server" Text=''<%# Bind("Question") %>'' /> </td> <td> <asp:TextBox ID="QuestionOrderTextBox" runat="server" Text=''<%# Bind("QuestionOrder") %>'' /> </td> <td> <asp:TextBox ID="AnswerExplanationTextBox" runat="server" Text=''<%# Bind("AnswerExplanation") %>'' /> </td> </tr> </EditItemTemplate> <EmptyDataTemplate> <table runat="server" style=""> <tr> <td> No data was returned.</td> </tr> </table> </EmptyDataTemplate> <InsertItemTemplate> <tr style=""> <td> <asp:ImageButton ID="InsertButton" ImageUrl="Images/icons/add24.png" ToolTip="Add" runat="server" CommandName="Insert" /> <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/clear24.png" ToolTip="Cancel" runat="server" CommandName="Cancel" /> </td> <%--<td>  </td>--%> <td> <asp:TextBox ID="QuestionTextBox" runat="server" Text=''<%# Bind("Question") %>'' /> </td> <td> <asp:TextBox ID="QuestionOrderTextBox" runat="server" Text=''<%# Bind("QuestionOrder") %>''/> </td> <td> <asp:TextBox ID="AnswerExplanationTextBox" runat="server" Text=''<%# Bind("AnswerExplanation") %>'' /> </td> </tr> </InsertItemTemplate> <ItemTemplate> <tr style=""> <td> <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="delete" runat="server" CommandName="Delete" /> <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" /> <asp:ImageButton ID="SelectButton" ImageUrl="Images/icons/select.png" ToolTip="Select" runat="server" CommandName="Select" /> <%--<asp:Button ID="SelectButton" runat="server" CommandName="Select" Text="Select" />--%> </td> <td> <asp:Label ID="QuestionLabel" runat="server" Text=''<%# Eval("Question") %>'' /> </td> <td> <asp:Label ID="QuestionOrderLabel" runat="server" Text=''<%# Eval("QuestionOrder") %>'' /> </td> <td> <asp:Label ID="AnswerExplanationLabel" runat="server" Text=''<%# Eval("AnswerExplanation") %>'' /> </td> </tr> </ItemTemplate> <LayoutTemplate> <div ><table id="thetable" width="97%" cellpadding="0px" cellspacing="0px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;"> <thead> <tr style="background-color:#C6D7B5;"> <th style="border-removed2px solid #003366; ">...</th> <th style="border-removed2px solid #003366; ">Question</th> <th style="border-removed2px solid #003366; ">Question Order</th> <th style="border-removed2px solid #003366; ">Answer Explanation</th> </tr> </thead> <tbody><tr id="itemPlaceholder" runat="server"></tr></tbody> </table></div> </LayoutTemplate> <SelectedItemTemplate> <tr style=""> <td> <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" /> <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" /> </td> <td> <asp:Label ID="QuestionLabel" runat="server" Text=''<%# Eval("Question") %>'' /> </td> <td> <asp:Label ID="QuestionOrderLabel" runat="server" Text=''<%# Eval("QuestionOrder") %>'' /> </td> <td> <asp:Label ID="AnswerExplanationLabel" runat="server" Text=''<%# Eval("AnswerExplanation") %>'' /> </td> </tr> </SelectedItemTemplate> </asp:ListView> </div> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%


ConnectionStrings:QuizSysDBConnectionString %>" SelectCommand="SELECT [Question].* FROM [Question] INNER JOIN [QuizContent] ON [QuizContent].[QuizID] = @QuizID" DeleteCommand="DELETE FROM [Question] WHERE [QuestionID] = @QuestionID" InsertCommand="INSERT INTO [Question] ([Question], [QuestionOrder], [AnswerExplanation]) VALUES (@Question, @QuestionOrder, @AnswerExplanation)" UpdateCommand="UPDATE [Question] SET [Question] = @Question, [QuestionOrder] = @QuestionOrder, [AnswerExplanation] = @AnswerExplanation WHERE [QuestionID] = @QuestionID"> <DeleteParameters> <asp:Parameter Name="QuestionID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="Question" Type="String" /> <asp:Parameter Name="QuestionOrder" Type="Int32" /> <asp:Parameter Name="AnswerExplanation" Type="String" /> <asp:ControlParameter ControlID="ListView1" Name="QuizID" PropertyName="SelectedValue" Type="Int32" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="Question" Type="String" /> <asp:Parameter Name="QuestionOrder" Type="Int32" /> <asp:Parameter Name="AnswerExplanation" Type="String" /> </UpdateParameters> <SelectParameters> <asp:ControlParameter ControlID="ListView1" Name="QuizID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> <br /><br /> <%--Third ListView that will contain the content of the quiz--%> <div align="center"> <asp:ListView ID="ListView3" runat="server" DataSourceID="SqlDataSource3" DataKeyNames="AnswerID" InsertItemPosition="LastItem"> <EditItemTemplate> <tr style=""> <td> <asp:ImageButton ID="UpdateButton" ImageUrl="Images/icons/update24.png" ToolTip="Update" runat="server" CommandName="Update" /> <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/cancel324.png" ToolTip="Cancel" runat="server" CommandName="Cancel" /> </td> <%--<td> <asp:Label ID="AnswerIDLabel1" runat="server" Text=''<%# Eval("AnswerID") %>'' /> </td>--%> <td> <asp:TextBox ID="AnswerTextBox" runat="server" Text=''<%# Bind("Answer") %>'' /> </td> </tr> </EditItemTemplate> <EmptyDataTemplate> <table runat="server" style=""> <tr> <td> No data was returned.</td> </tr> </table> </EmptyDataTemplate> <InsertItemTemplate> <tr style=""> <td> <asp:ImageButton ID="InsertButton" ImageUrl="Images/icons/add24.png" ToolTip="Add" runat="server" CommandName="Insert" /> <asp:ImageButton ID="CancelButton" ImageUrl="Images/icons/clear24.png" ToolTip="Cancel" runat="server" CommandName="Cancel" /> </td> <%--<td>  </td>--%> <td> <asp:TextBox ID="AnswerTextBox" runat="server" Text=''<%# Bind("Answer") %>''/> </td> </tr> </InsertItemTemplate> <ItemTemplate> <tr style=""> <td> <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" /> <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" /> </td> <%--<td> <asp:Label ID="AnswerIDLabel" runat="server" Text=''<%# Eval("AnswerID") %>'' /> </td>--%> <td> <asp:Label ID="AnswerLabel" runat="server" Text=''<%# Eval("Answer") %>'' /> </td> </tr> </ItemTemplate> <LayoutTemplate> <div ><table id="thetable" width="97%" cellpadding="0px" cellspacing="0px" style="margin:0px 0px 0px 0px; border:2px solid #003366; font-size:13px; font-weight:bold;"> <thead> <tr style="background-color:#C6D7B5;"> <th style="border-removed2px solid #003366; ">...</th> <th style="border-removed2px solid #003366; ">Answer</th> </tr> </thead> <tbody><tr id="itemPlaceholder" runat="server"></tr></tbody> </table></div> </LayoutTemplate> <SelectedItemTemplate> <tr style=""> <td> <asp:ImageButton ID="DeleteButton" ImageUrl="Images/icons/delete24.png" ToolTip="Delete" runat="server" CommandName="Delete" /> <asp:ImageButton ID="EditButton" ImageUrl="Images/icons/edit24.png" ToolTip="Edit" runat="server" CommandName="Edit" /> </td> <td> <asp:Label ID="AnswerLabel" runat="server" Text=''<%# Eval("Answer") %>'' /> </td> </tr> </SelectedItemTemplate> </asp:ListView> </div> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%


ConnectionStrings:QuizSysDBConnectionString %>" SelectCommand="SELECT [Answers].* FROM [Answers] INNER JOIN [QuizContent] ON [QuizContent].QuestionID = @QuestionID" DeleteCommand="DELETE FROM [Answers] WHERE [AnswerID] = @AnswerID" InsertCommand="INSERT INTO [Answers] ([Answer]) VALUES (@Answer)" UpdateCommand="UPDATE [Answers] SET [Answer] = @Answer WHERE [AnswerID] = @AnswerID"> <DeleteParameters> <asp:Parameter Name="AnswerID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="Answer" Type="String" /> <asp:ControlParameter ControlID="ListView2" Name="QuestionID" PropertyName="SelectedValue" Type="Int32" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="Answer" Type="String" /> </UpdateParameters> <SelectParameters> <asp:ControlParameter ControlID="ListView2" Name="QuestionID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource>



**NOTE:**
I don''t have any code-behind. And again the problem is as following: when I run the code, I will see the three ListView controls. It should show only one of them. And when the user selects one of the rows, the second ListView will be displayed and so on for the third ListView.


这篇关于在第一个ListView中选择一行后,如何使第二个ListView显示(可见)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆