Update Panel Posting back with Listview - c#

I have an update panel inside of an accordian control, two things should cause an async postback:
1) When I click the Image button
2) I click the paging.
Both things work fine, but always cause a full postback.
<asp:UpdatePanel ID="updListView" runat="server" ChildrenAsTriggers="True">
<ContentTemplate>
<asp:ListView ID="dlNewLeads" runat="server" DataSourceID="sdsLeads" OnItemCommand="dlNewLeads_OnItemCommand">
<ItemTemplate>
<table style="width: 642px;">
<tr>
<td style="width: 421px;">
<asp:Label ID="lblTitle" runat="server" Text="Name" class="repeater-title"></asp:Label><br/>
</td>
<td style="width: 421px;">
<asp:Label ID="Label3" runat="server" Text="Phone" class="repeater-title"></asp:Label><br/>
</td>
<td style="width: 421px;">
<asp:Label ID="Label1" runat="server" Text="Time of Lead" class="repeater-title"></asp:Label><br/>
</td>
</tr>
<tr>
<td style="width: 421px;">
<asp:linkbutton ClientIDMode="AutoID" ID="btnRem" CommandName="SetAsContacted" runat="server" causesvalidation="false" commandargument='<%# Eval("Id") %>'>
<asp:image id="Image2" runat="server" imageurl="~/Images/x.jpg"/>
</asp:linkbutton> <asp:HyperLink Text='<%# Eval("FullName") %>' NavigateUrl='<%# GetLink(Eval("ID").ToString()) %>' runat="server"></asp:HyperLink>
</td>
<td style="width: 421px;">
<asp:Label ID="Label4" runat="server" Text='<%# Eval("Phone") %>' class="repeater-text"></asp:Label>
</td>
<td style="width: 421px;"><asp:Label ID="Label2" runat="server" Text='<%# Eval("TimeOfLead") %>' class="repeater-text"></asp:Label>
<td style="max-width: 76px; min-width: 76px;">
</td><br/>
</td>
</tr>
</table>
<div style="background-color: #dae5e7; height: 1px; width: 590px;"></div>
<br/>
</ItemTemplate>
</asp:ListView>
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="dlNewLeads" PageSize="5">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True"/>
</Fields>
</asp:DataPager>
</ContentTemplate>
</asp:UpdatePanel>
I'm binding the ListView with a SqlDataSource
<asp:SqlDataSource ID="sdsLeads" runat="server" ConnectionString="<%$ ConnectionStrings:SjkConnectionString %>" SelectCommand="SELECT [Id], [FullName], [TimeOfLead], [Phone] FROM [RequestContacts] WHERE (([IsAnswered] = #IsAnswered) AND ([Id] = #Id))">
<SelectParameters>
<asp:Parameter DefaultValue="False" Name="IsAnswered" Type="Boolean" />
<asp:Parameter DefaultValue="0" Name="Id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Then on Form Page Load
If(!IsPostBack)
sdsLeads.SelectParameters["Id"].DefaultValue = locationId.ToString();

Come to find out, something in my web.config file causing it. I don't know which line exactly so I can't offer a solution to anyone.
I replaced my web.config file which I changed last night with my backup and it worked right away.

Related

Render UserControl in Same line as other controls in a <td>

I want to render Usercontrol in the same line as my other controls in . By default, it renders in new line for user control.
Here is my Markup
<tr>
<td>
<asp:ContentPlaceHolder ID="TitleContentPlaceHolder" runat="server">
<asp:Label ID="lblTitle" runat="server" EnableTheming="False" Font-Size="Small" ForeColor="Green"
Font-Bold="True" Style="margin-left: 18px"></asp:Label>
<asp:HyperLink ID="gotoHyperLink" Visible="false" EnableTheming="False" Font-Size="Small"
ForeColor="Green" Font-Bold="True" Style="margin-left: 2px" runat="server" NavigateUrl=""
Target="_blank">- To Wiki</asp:HyperLink>
<uc1:GoToRequestControl ID="GoToRequestControl1" runat="server" />
</asp:ContentPlaceHolder>
</td>
</tr>
I want to render the UC1 in the same line as previous two controls in Div if possible after some spacing to the right. Any fix on how to achieve this?
My User Control is designed using despite that I want it to be on same line. Here is my Usercontrol's HTML
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:Panel runat="server" DefaultButton="btnGo" BackColor="Transparent">
<table style="margin-left:18px">
<tr valign="top">
<td>
<b><asp:Literal ID="Label1" runat="server" Text="Coeus Request ID: " EnableTheming="False"></asp:Literal></b>
</td>
<td>
<asp:TextBox ID="tbRequestId" runat="server" EnableTheming="false" Width="260px"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" OnClientClick="CheckLock();"
CausesValidation="False" UseSubmitBehavior="false" />
</td>
<td>
<asp:Label ID="lblStatus" runat="server" Text="" EnableTheming="False" ForeColor="Red"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>

ListView not updating after selecting value from DropDownlist

For a exercise at school i need to make a website that fetches rows from a SQL-database after selecting a type ( in my case bikes ). I've got most of it working except for the ListView, it won't update when i select a option in the dropdownlist. I think it is a SQL Stored Procedure error but i can't seem to find the problem.
Stored Procedures;
To fetch the types from the db that need to be shown in the dropdownlist (this works)
CREATE PROCEDURE [dbo].[Procedure2]
AS
select a_type
from Artikelen
group by a_type
order by a_type
RETURN
This one is to fetch the rows that have the type the user has selected from the dropdownlist. #type should be the selected value in the dropdownlist.
CREATE PROCEDURE [dbo].[OphaalFietsBijType]
#type varchar(50)
AS
select artikelnr, a_omschr, a_prijs
from Artikelen
where a_type = #type
RETURN
ASP.NET Code
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="A_type" DataValueField="A_type">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="Procedure2" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="artikelnr" DataSourceID="Ophalen">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="artikelnrLabel" runat="server" Text='<%# Eval("artikelnr") %>' />
</td>
<td>
<asp:Label ID="a_omschrLabel" runat="server" Text='<%# Eval("a_omschr") %>' />
</td>
<td>
<asp:Label ID="a_prijsLabel" runat="server" Text='<%# Eval("a_prijs") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="artikelnrLabel1" runat="server" Text='<%# Eval("artikelnr") %>' />
</td>
<td>
<asp:TextBox ID="a_omschrTextBox" runat="server" Text='<%# Bind("a_omschr") %>' />
</td>
<td>
<asp:TextBox ID="a_prijsTextBox" runat="server" Text='<%# Bind("a_prijs") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="artikelnrTextBox" runat="server" Text='<%# Bind("artikelnr") %>' />
</td>
<td>
<asp:TextBox ID="a_omschrTextBox" runat="server" Text='<%# Bind("a_omschr") %>' />
</td>
<td>
<asp:TextBox ID="a_prijsTextBox" runat="server" Text='<%# Bind("a_prijs") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="artikelnrLabel" runat="server" Text='<%# Eval("artikelnr") %>' />
</td>
<td>
<asp:Label ID="a_omschrLabel" runat="server" Text='<%# Eval("a_omschr") %>' />
</td>
<td>
<asp:Label ID="a_prijsLabel" runat="server" Text='<%# Eval("a_prijs") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">artikelnr</th>
<th runat="server">a_omschr</th>
<th runat="server">a_prijs</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="artikelnrLabel" runat="server" Text='<%# Eval("artikelnr") %>' />
</td>
<td>
<asp:Label ID="a_omschrLabel" runat="server" Text='<%# Eval("a_omschr") %>' />
</td>
<td>
<asp:Label ID="a_prijsLabel" runat="server" Text='<%# Eval("a_prijs") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="Ophalen" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="OphaalFietsBijType" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="type" SessionField="#type" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
You are using a SessionParameter but are not setting the session variable anywhere. You also don't need to, since you are getting the value, without any need for complex logic, directly from your DropDownList. What you are after is ControlParameter.
Simply change your parameter to the following:
<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="type" Type="String" />

LinqDataSource WhereParameters with a dropdownlist and a field from the database

I will like to perform a LINQ Listview where clause with two items for the where clause: the first one is coming from the Dropdownlist selection (this work fine). I want to add another selection from the a table field from my database (isAvailable). Can you explain me how to populate the request for the where clause using the table field isAvaiable (bool type). I am doing this in C#. Here is the code:
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="ApointmentDataContext"
EnableDelete="True" EnableInsert="True" EnableUpdate="True" EntityTypeName=""
TableName="RendezVous" AutoGenerateWhereClause="True">
<WhereParameters>
<asp:ControlParameter
Name="DoctorName"
ControlID="DropDownList1"
PropertyName="SelectedValue"
Type="String" />
</WhereParameters>
</asp:LinqDataSource>
<div class="center">
<asp:Label ID="lblDoctor" runat="server" Text="Choose a name"> </asp:Label>
<div class="value-right">
<asp:DropDownList ID="DropDownList1" runat="server" Width="180px" AutoPostBack="true" >
<asp:ListItem Text="Doct A" Value="Doc A" />
<asp:ListItem Text="Doct B" Value="Doc B" />
<asp:ListItem Text="Doct C" Value="Doc C" />
</asp:DropDownList>
</div>
</div>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server"></th>
<th runat="server">DoctName</th>
<th runat="server">date</th>
<th runat="server">hour</th>
<th runat="server">patientName</th>
<th runat="server">isAvailable</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="lblDoctorName" runat="server" Text='<%#
Eval("DoctorName") %>' />
</td>
<td>
<asp:Label ID="lblDate" runat="server" Text='<%# Eval("date") %>' />
</td>
<td>
<asp:Label ID="lblhour" runat="server" Text='<%# Eval("hour") %>' />
</td>
<td>
<asp:Label ID="lblPatient" runat="server" Text='<%# Eval("patientName") %>'
/>
</td>
<td>
<asp:Label ID="isAvailable" runat="server" Text='<%# Eval("isAvailable") %>'
/>
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
I need to put the field isAvailable inside of the where clause, can figure it out. Thanks

How to show/display the second ListView after selecting a row in the first 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:
quiz information, question information (based on the selected quiz on the first ListView), and answers information (based on the selected question on the second ListView)
I have the following database design:
QuizContent Table: ID, QuizID, QuestionID, AnswerID, isCorrect
Quiz Table: QuizID, Title, Description, isSent
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 so on for the third ListView. I am only facing problem in showing the second ListView. I don't know how to show it.
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:
<div align="center">
<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-bottom:2px solid #003366; ">...</th>
<th style="border-bottom:2px solid #003366; ">Title</th>
<th style="border-bottom:2px 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" visible="false">
<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-bottom:2px solid #003366; ">...</th>
<th style="border-bottom:2px solid #003366; ">Question</th>
<th style="border-bottom:2px solid #003366; ">Question Order</th>
<th style="border-bottom:2px 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-bottom:2px solid #003366; ">...</th>
<th style="border-bottom:2px 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.
OK I had already helped you with a similar question, this time, I decided to see exactly the problem so I created tables locally with your structure and I could replicate your problem
Basically your queries were wrong and I do not know how you were expecting to hide/show the ListView controls without writing code behind nor JavaScript...
I must say that I agree with #GrayFox374 you should show more initiative...
Well anyhow...
I already tested this code and I think it's exactly what you are looking for:
Basically when the page loads only the quizes table is visible, when a quiz is selected, if it has records, the questions table is shown and finally when you select a question, the answers table is shown only if it contains data.
Output
When page is loaded
When a quiz is selected
When a question is selected
Code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.InitializeListView(this.ListView2);
this.InitializeListView(this.ListView3);
}
}
protected void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitializeListView(this.ListView2);
this.InitializeListView(this.ListView3);
}
protected void ListView2_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitializeListView(this.ListView3);
}
private void InitializeListView(ListView listView)
{
listView.SelectedIndex = -1;
listView.EditIndex = -1;
listView.DataBind();
listView.Visible = listView.Items.Count > 0;
}
ASPX
Note: just showing the code I updated
<asp:ListView ID="ListView1" runat="server" DataKeyNames="QuizID"
DataSourceID="SqlDataSource1" InsertItemPosition="LastItem"
onselectedindexchanged="ListView1_SelectedIndexChanged" >
.....
<asp:ListView ID="ListView2" runat="server" DataSourceID="SqlDataSource2"
DataKeyNames="QuestionID" InsertItemPosition="LastItem"
onselectedindexchanged="ListView2_SelectedIndexChanged">
....
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:QuizSysDBConnectionString %>"
SelectCommand="SELECT QuestionID, Question, QuestionOrder, AnswerExplanation
FROM Question
WHERE (QuestionID IN
(SELECT DISTINCT QuestionID
FROM QuizContent
WHERE (QuizID = #QuizID)))"
<SelectParameters>
<asp:ControlParameter ControlID="ListView1" Name="QuizID" DefaultValue="0"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
.....
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:QuizSysDBConnectionString %>"
SelectCommand="SELECT AnswerID, Answer
FROM Answers
WHERE (AnswerID IN
(SELECT DISTINCT AnswerID
FROM QuizContent
WHERE (QuestionID = #QuestionID)))"
<SelectParameters>
<asp:ControlParameter ControlID="ListView2" Name="QuestionID" DefaultValue="0"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
Note, if this doesn't work I would strongly recommend you to run the queries manually against your database to discard data issues
Well that's it I hope I didn't forget to add more modifications
I remember helping you on a related issue to this same project - How to develop this ListView which depends on another ListView? -which you never followed up on. Looking at your history, you seem to be intent on having that Stack Overflow community do just about all of your work for you. Nearly every question is about a different aspect of this same project.
rant->I would feel bad about this approach if I were you, because you
are not demonstrating the initiative, the drive to take ownership over
your craft. You seem content to let others toil while you reap the
bounty, while your level of understanding is barely nudged from its
starting point. But whatever... some of us just like to solve
problems and always strive to widen our skillset. We just wish more
of our colleagues which as passionate and committed to the craft.
<- end rant
solution->
The same things I mentioned in your other post apply here. To start with, you have questionable design. Here, you want to bind ListView2 (Questions) to ListView1 (Quizzes), where there is nothing in the schema to join them!!! You could do some esoteric, convoluted joins to link Questions to Quizzes through the QuizContents table's keys to both of the other tables, but in your presentation, QuizContents comes AFTER those two, so even that wouldn't work. This flat out cannot be done in your current setup. Look at what I recommended in the above mentioned link, and even if you disagree, if you take a little more time out to think about the design first before rushing to hack away and code as you go, you'll see that what you are attempting is not going to work. Revamp your design. solution->

Keep page position on postback

I have a problem:
<asp:Label ID="Label1" runat="server" Text="Name" CssClass="left"></asp:Label>
<asp:LinkButton ID="LinkEdit" runat="server" CssClass="right_bottom"
onclick="LinkEdit_Click" Height="16px">edit</asp:LinkButton>
<asp:LinkButton ID="Linkhide" runat="server" CssClass="right_bottom"
onclick="Linkhide_Click" Visible="False" hide</asp:LinkButton>
<br />
<hr style="width: 740px; height: -6px; margin-left: 0px; " />
<asp:Label ID="labelFullname" runat="server" Text="Full Name" CssClass="left_top"></asp:Label>
<asp:Label ID="labelNameDisplay" runat="server" Text="Put name here" CssClass="right_top"></asp:Label>
<br />
<asp:Panel ID="panelName" runat="server" Height="240px" Visible="False" CssClass="panel_top"
style="text-align: left;">
<asp:Label ID="Label8" runat="server" CssClass="left" Text="Please allow 24 hours for name changes to take effect."></asp:Label>
<div align="center"><br />
<br />
<table>
<tr>
<td class="label_new">
<asp:Label ID="Label4" runat="server" Text="Full Name:" ToolTip="Name Displayed"></asp:Label>
</td>
<td align="left">
<asp:DropDownList ID="DropDownList1" runat="server" BorderStyle="Groove"
Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="25px"
valign="middle" Width="250px">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="label_new">
<asp:Label ID="Label2" runat="server" Text="First Name:"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtFirstName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px"
valign="middle" Width="242px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="label_new">
<asp:Label ID="Label9" runat="server" Text="Middle Name:"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtMiddleName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px"
valign="middle" Width="242px" onfocus="if (this.value == 'optional') { this.value=''; this.style.color='black';}" />
</td>
</tr>
<tr>
<td class="label_new">
<asp:Label ID="Label10" runat="server" Text="Last Name:"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtLastName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px"
valign="middle" Width="242px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSaveChanges" runat="server" Text="Save Changes"
onclick="btnSaveChanges_Click" />
</td>
</tr>
</table>
</div>
</asp:Panel>
I have 4 panels in this format just like ACCOUNT SETTINGS on facebook.
My problem here is when I show the panel it just jump to the top of the page.
I would like to do it just as the way facebook is doing. Click and be on at the same position of where you clicked.
You can set the MaintainScrollPositionOnPostback property on your page:
Page.MaintainScrollPositionOnPostback = true;
or put it in the page declaration
<%# Page MaintainScrollPositionOnPostback="true" %>
I'm not entirely sure I what you are asking for. Facebook uses a lot of ajax style callbacks which means that the page doesn't reload using asp .net style postbacks. If you're just starting out I'd recommend you trying placing your code into an Ajax .Net UpdatePanel whilst you learn the details of Ajax / JSON / XMLHttpRequest etc.
If you're simply looking to make sure the browser window remains at the same scrollbar position after a postback then set the page to use the MaintainScrollPositionOnPostback="true" directive.

Categories

Resources