Why my datalist is displaying only first image? - c#

I have db which contains products with columns: image1, image2, image3. I'm displaying this datalist and only first picture occurs there. On the others images I see that redirection is fine, but it isn't showing them up.
Markup:
<asp:DataList ID="DataList2" runat="server" DataKeyField="ID" DataSourceID="SqlDataSource1">
<ItemTemplate>
<table>
<tr>
<td rowspan="2">
<asp:HyperLink ID="HyperLink3" runat="server" ImageUrl='<%# Eval("image1", "{0}") %>' data-lightbox="imageset" Height="150px" Width="150px" ImageHeight="150px" ImageWidth="150px" NavigateUrl='<%# Eval("image1", "{0}") %>'></asp:HyperLink>
</td>
<td width="600px"><asp:Label ID="nazwaLabel" runat="server" Text='<%# Eval("nazwa") %>' CssClass="produktNazwa" />
</tr>
<tr>
<td><asp:Label ID="cenaLabel" runat="server" Text='<%# Eval("cena", "{0} PLN") %>' CssClass="produktCena" /> </td>
</tr>
<tr>
<td>
<asp:HyperLink ID="HyperLink4" runat="server" ImageUrl='<%# Eval("image2", "{0}") %>' data-lightbox="imageset" Height="150px" Width="150px" ImageHeight="150px" ImageWidth="150px" NavigateUrl='<%# Eval("image2", "{0}") %>'></asp:HyperLink>
</td>
<td><asp:Label ID="opisLabel" runat="server" Text='<%# Eval("opis") %>' CssClass="produktOpis" /></td>
</tr>
<tr>
<td>
<asp:HyperLink ID="HyperLink5" runat="server" ImageUrl='<%# Eval("image3", "{0}") %>' data-lightbox="imageset" Height="150px" Width="150px" ImageHeight="150px" ImageWidth="150px" NavigateUrl='<%# Eval("image3", "{0}") %>'></asp:HyperLink>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Produkty] WHERE ([ID] = #ID)">
<SelectParameters>
<asp:ControlParameter ControlID="Label1" Name="ID" PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Any ideas?

Related

Change visibility of button in gridview for different users

I have a gridview of comments which shows a delete button for the comment made by logged in user.I mean logged in uder can delete his own comments ONLY.
I have tried the below but it doesnt show the delete button for any user.
<asp:GridView ID="GridView1" runat="server" GridLines="None" AutoGenerateColumns="False" Width="540px" ShowHeader="False" CellPadding="4" ForeColor="Black" OnRowCommand="GridView1_RowCommand" DataKeyNames="CommentId">
<EmptyDataTemplate>
---No comments on this event---
</EmptyDataTemplate>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table style="width:540px;background-color:white">
<tr>
<td style="width:60px" rowspan="3">
<asp:Image ID="imgUser" Width="50px" Height="50px" ImageUrl='<%# Bind("ProfilePicPath") %>' runat="server" style="border: 2px inset #C0C0C0" />
</td>
<td style="width:480px;border-bottom:solid 1px #999999">
<asp:Label ID="lblCommentator" runat="server" Text='<%# Bind("FirstName") %>' style="color: #336699"></asp:Label>
on
<asp:Label ID="lblCommentTime" runat="server" Text='<%# Bind("CommentTime") %>' style="font-weight: 700"></asp:Label>
</td>
</tr>
<tr>
<td style="width:480px;vertical-align:top">
<asp:Label ID="lblComment" runat="server" Text='<%# Bind("Comment") %>'></asp:Label>
</td>
</tr>
<tr>
<td style="width:480px;vertical-align:top;text-align:right">
<asp:HiddenField ID="hfUserId" Value='<%# Bind("UserId") %>' runat="server" />
<asp:LinkButton ID="btnDeleteComment" runat="server" Visible='<%# Session["UserId"] == Eval("UserId") %>' CommandArgument='<%#Eval("CommentId")%>' CommandName="Delete">Delete</asp:LinkButton>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SportsActiveConnectionString %>" SelectCommand="spExtractEventComments" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter Name="Eventid" Type="Int32" ControlID="lblEventId" />
</SelectParameters>
</asp:SqlDataSource>
As you can see above, i am comparing the current user(stored in session) to the UserId of that comment.
<asp:LinkButton ID="btnDeleteComment" runat="server" Visible='<%# Session["UserId"] == Eval("UserId") %>'.....
Thanks in advance
There is example :
vb.net :
<asp:LinkButton ID="btnDeleteComment" runat="server" Visible='<%# If(Session("UserId") = Eval("UserId"), "True", "False")%>'></asp:LinkButton>
c# (I think) :
<asp:LinkButton ID="btnDeleteComment" runat="server" Visible='<%# If(Session["UserId"] == Eval("UserId").ToString() ? true : false)%>'></asp:LinkButton>
Using If for checking are values match (Tested and working)
If(condition,do what You want if result is True, do what You want if result if False)

Procedure or function has too many arguments specified, using: sql server stored procedure, Listview

I have the following code for my Edit Stored Procedure:
CREATE PROCEDURE [dbo].[sp_EditDates]
#ID int,
#PublishYear int,
#PublishMonth int,
#PayDte varchar(200),
#PublishDte varchar(200)
AS
BEGIN
-- Insert statements for procedure here
UPDATE PaymentAndPublishingDates SET PublishYear = #PublishYear, PublishMonth = #PublishMonth, PayDte = #PayDte, PublishDte = #PublishDte
WHERE ID=#ID;
END
And the following for my Select stored procedure:
CREATE PROCEDURE [dbo].[sp_RetrieveAllDates]
AS BEGIN SELECT DISTINCT
PaymentAndPublishingDates.ID, PaymentAndPublishingDates.PublishYear,
PaymentAndPublishingDates.PublishMonth,
CONVERT(VARCHAR,PaymentAndPublishingDates.PayDte,106)AS PayDate,
CONVERT(VARCHAR,PaymentAndPublishingDates.PublishDte,120) AS PublishDate
FROM PaymentAndPublishingDates
END
And I have a datasource like this:
<asp:ListView ID="ListView1" runat="server" DataSourceID="Payment_Dates"
InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="background-color:#FFF8DC;">
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="PublishYearLabel" runat="server"
Text='<%# Eval("PublishYear") %>' />
</td>
<td>
<asp:Label ID="PublishMonthLabel" runat="server"
Text='<%# Eval("PublishMonth") %>' />
</td>
<td>
<asp:Label ID="PayDateLabel" runat="server" Text='<%# Eval("PayDate") %>' />
</td>
<td>
<asp:Label ID="PublishDateLabel" runat="server"
Text='<%# Eval("PublishDate") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="background-color:#008A8C;color: #FFFFFF;">
<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="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:TextBox ID="PublishYearTextBox" runat="server"
Text='<%# Bind("PublishYear") %>' />
</td>
<td>
<asp:TextBox ID="PublishMonthTextBox" runat="server"
Text='<%# Bind("PublishMonth") %>' />
</td>
<td>
<asp:TextBox ID="PayDateTextBox" runat="server" Text='<%# Bind("PayDate") %>' />
</td>
<td>
<asp:TextBox ID="PublishDateTextBox" runat="server"
Text='<%# Bind("PublishDate") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<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>
</td>
<td>
<asp:TextBox ID="PublishYearTextBox" runat="server"
Text='<%# Bind("PublishYear") %>' />
</td>
<td>
<asp:TextBox ID="PublishMonthTextBox" runat="server"
Text='<%# Bind("PublishMonth") %>' />
</td>
<td>
<asp:TextBox ID="PayDateTextBox" runat="server" Text='<%# Bind("PayDate") %>' />
</td>
<td>
<asp:TextBox ID="PublishDateTextBox" runat="server"
Text='<%# Bind("PublishDate") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;">
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="PublishYearLabel" runat="server"
Text='<%# Eval("PublishYear") %>' />
</td>
<td>
<asp:Label ID="PublishMonthLabel" runat="server"
Text='<%# Eval("PublishMonth") %>' />
</td>
<td>
<asp:Label ID="PayDateLabel" runat="server" Text='<%# Eval("PayDate") %>' />
</td>
<td>
<asp:Label ID="PublishDateLabel" runat="server"
Text='<%# Eval("PublishDate") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="1"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr runat="server" style="background-color:#DCDCDC;color: #000000;">
<th runat="server">
</th>
<th runat="server">
ID</th>
<th runat="server">
PublishYear</th>
<th runat="server">
PublishMonth</th>
<th runat="server">
PayDate</th>
<th runat="server">
PublishDate</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server"
style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="PublishYearLabel" runat="server"
Text='<%# Eval("PublishYear") %>' />
</td>
<td>
<asp:Label ID="PublishMonthLabel" runat="server"
Text='<%# Eval("PublishMonth") %>' />
</td>
<td>
<asp:Label ID="PayDateLabel" runat="server" Text='<%# Eval("PayDate") %>' />
</td>
<td>
<asp:Label ID="PublishDateLabel" runat="server"
Text='<%# Eval("PublishDate") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="Payment_Dates" runat="server"
ConnectionString="<%$ ConnectionStrings:TUT_ElectronicPayslipsConnectionString %>"
InsertCommand="sp_CapturePayDate" InsertCommandType="StoredProcedure"
SelectCommand="sp_RetrieveAllDates" SelectCommandType="StoredProcedure"
UpdateCommand="sp_EditDates" UpdateCommandType="StoredProcedure">
<InsertParameters>
<asp:Parameter Name="PublishYear" Type="Int32" />
<asp:Parameter Name="PublishMonth" Type="Int32" />
<asp:Parameter Name="PayDte" Type="String" />
<asp:Parameter Name="PublishDte" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="PublishYear" Type="Int32" />
<asp:Parameter Name="PublishMonth" Type="Int32" />
<asp:Parameter Name="PayDte" Type="String" />
<asp:Parameter Name="PublishDte" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
The data displays fine but when I try to edit fields I get this error "Procedure or function sp_EditDates has too many arguments specified".
Please Help

SqlDataSource UpdateCommand parameters not changing

I have a FormView with an UpdateButton and a SqlDataSource which are below. My updatebutton always update the Sil table with the same values (the values at the first line of my gridview), I couldn't figure out why.
<asp:FormView ID="frm_Benefit" runat="server" DataKeyNames="ID" DataSourceID="sds_Benefits"
OnItemInserted="frm_Benefit_ItemInserted" OnItemUpdated="frm_Benefit_ItemUpdated">
<EditItemTemplate>
<table class="formview">
<tr>
<td>
Code:
</td>
<td>
<asp:TextBox ID="CodeTextBox" runat="server" Text='<%# Bind("Code") %>' />
</td>
</tr>
<tr>
<td>
Name:
</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
</td>
</tr>
<tr>
<td>
HRName:
</td>
<td>
<asp:TextBox ID="HRNameTextBox" runat="server" Text='<%# Bind("HRName") %>' />
</td>
</tr>
<tr>
<td>
Description:
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'
TextMode="MultiLine" MaxLength="200" />
</td>
</tr>
<tr>
<td>
Associated Url:
</td>
<td>
<asp:TextBox ID="UrlTextBox" runat="server" Text='<%# Bind("Url") %>' MaxLength="100" />
</td>
</tr>
<tr>
<td>
BenefitType:
</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="sds_BenefitTypes"
DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("BenefitTypeID") %>'>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Cost:
</td>
<td>
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' />
</td>
</tr>
<tr>
<td>
Cost Type:
</td>
<td>
<asp:DropDownList ID="CostTypeDropDown" runat="server" DataSourceID="sds_CostTypes"
DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("CostTypeID") %>'>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Quantity Type:
</td>
<td>
<asp:DropDownList ID="QuantityTypeDropDown" runat="server" DataSourceID="sds_QuantityTypes"
DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("QuantityTypeID") %>'>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Quantity Entry On Add:
</td>
<td>
<asp:CheckBox ID="QuantityEntryOnAddCheckBox" runat="server" Checked='<%# Bind("QuantityEntryOnAdd") %>' />
</td>
</tr>
<tr>
<td>
Quantity Entry On Remove:
</td>
<td>
<asp:CheckBox ID="QuantityEntryOnRemoveCheckBox" runat="server" Checked='<%# Bind("QuantityEntryOnRemove") %>' />
</td>
</tr>
<tr>
<td>
Bonus Ratio:
</td>
<td>
<asp:TextBox ID="BonusRatioTextBox" runat="server" Text='<%# Bind("BonusRatio") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
ApplyIncomeTax:
</td>
<td>
<asp:CheckBox ID="ApplyIncomeTaxCheckBox" runat="server" Checked='<%# Bind("ApplyIncomeTax") %>' />
</td>
</tr>
<tr>
<td>
ApplyStampTax:
</td>
<td>
<asp:CheckBox ID="ApplyStampTaxCheckBox" runat="server" Checked='<%# Bind("ApplyStampTax") %>' />
</td>
</tr>
<tr>
<td class="style1">
ApplySocialSecurityTax:
</td>
<td class="style1">
<asp:CheckBox ID="ApplySocialSecurityTaxCheckBox" runat="server" Checked='<%# Bind("ApplySocialSecurityTax") %>' />
</td>
</tr>
<tr>
<td>
Applicable Location:
</td>
<td>
<asp:DropDownList ID="CostTypeDropDown1" runat="server" DataSourceID="sds_Locations"
DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("ApplicableLocationID") %>'>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update" Style="display: none" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" Style="display: none" />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="sds_Benefits" runat="server" ConnectionString="<%$ ConnectionStrings:ConnFlexibleBenefitsDB %>"
SelectCommand="SELECT * FROM [View_Benefits]"
UpdateCommand="UPDATE [Sil] SET [Code] = #Code, [HRName] = #HRName WHERE [Id] = #Id">
<UpdateParameters>
<asp:Parameter Name="Code" Type="String" />
<asp:Parameter Name="HRName" Type="String" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
And this is my gridview:
<asp:GridView ID="grd_Benefits" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
CssClass="gridTable" DataSourceID="sds_Benefits" OnRowCommand="grd_Benefits_RowCommand">
<RowStyle CssClass="gridRow" />
<FooterStyle CssClass="gridFooter" />
<SelectedRowStyle CssClass="gridSelectedRow" />
<HeaderStyle CssClass="gridHeader" />
<AlternatingRowStyle CssClass="gridAlternatingRow" />
<EmptyDataTemplate>
No records found.
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" />
<asp:BoundField DataField="HRName" HeaderText="HRName" SortExpression="HRName" />
<asp:TemplateField HeaderText="Benefit Type" SortExpression="BenefitType.Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("BenefitTypeName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Cost" HeaderText="Cost" SortExpression="Cost" />
<asp:TemplateField HeaderText="Cost Type">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("CostTypeName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity Type">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("QuantityTypeName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbSelect" runat="server" CausesValidation="False" CommandName="ViewRecord"
Text="<img border='0' alt='Edit' src='../images/zoom.gif' />" CommandArgument='<%# Container.DataItemIndex %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<HeaderTemplate>
<asp:LinkButton ID="lbInsert" runat="server" CausesValidation="false" CommandName="NewRecord"
Text="<img border='0' alt='New' src='../images/new.gif' />" CommandArgument='<%# Container.DataItemIndex %>'
ForeColor="White"></asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="EditRecord"
Text="<img border='0' alt='Edit' src='../images/edit.gif' />" CommandArgument='<%# Container.DataItemIndex %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
RowCommand:
protected void grd_Benefits_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ViewRecord")
{
grd_Benefits.SelectedIndex = int.Parse(e.CommandArgument.ToString());
frm_Benefit.ChangeMode(FormViewMode.ReadOnly);
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFormViewView", "<script type=\"text/javascript\">showFormViewView();</script>");
}
else if (e.CommandName == "NewRecord")
{
frm_Benefit.ChangeMode(FormViewMode.Insert);
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFormViewInsert", "<script type=\"text/javascript\">showFormViewInsert();</script>");
}
else if (e.CommandName == "EditRecord")
{
grd_Benefits.SelectedIndex = int.Parse(e.CommandArgument.ToString());
frm_Benefit.ChangeMode(FormViewMode.Edit);
Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowFormViewEdit", "<script type=\"text/javascript\">showFormViewEdit();</script>");
}
}
Seeing your Markups and taking it as it is, the issue is with the FormView.
You have not set the AllowPaging="true" for FormView. So every time the FormView displays, it will just Display only the First Row of all the data records retrieved.
[ Note that Form View displays only one single record at a time ].
So every time you are selecting 'Edit' in Form View, you are actually editing the First record only ( which is indeed the First row of GridView).
Set the AllowPaging property to true for FormView.
<asp:FormView ID="frm_Benefit" runat="server" DataKeyNames="CustomerID"
DataSourceID="sds_Benefits" OnItemUpdated="frm_Benefit_ItemUpdated"
AllowPaging="true">
After that using the Paging index, navigate to any record you want to change and edit it as seen below.

How to add a checkbox and bindining it in this ListView?

I have a ListView in the Quiz Management web-based application that I am developing and I am binding it to the Answers table in the Database. Now, I want to add a column with a CheckBox control that will be bound to (isCorrect) column in the QuizContent table in the database. I don't know how to do that, so could you please help me in this?
FYI, I have the following database design:
QuizContent Table: ID, QuizID, QuestionID, AnswerID, isCorrect
Quiz Table: QuizID, Title, Description
Question Table: QuestionID, Question, QuestionOrder, AnswerExplanation
Answers Table: AnswerID, Answer
My ASP.NET code:
<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:TextBox ID="AnswerTextBox" runat="server"
Text='<%# Bind("Answer") %>' />
</td>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true"
Text='<%# Bind("isCorrect") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table id="Table2" 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>
<asp:TextBox ID="AnswerTextBox" runat="server"
Text='<%# Bind("Answer") %>'/>
</td>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true"
Text='<%# Bind("isCorrect") %>' />
</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="AnswerLabel" runat="server" Text='<%# Eval("Answer") %>' />
</td>
<td>
<asp:Label ID="IsCorrectLabel" runat="server" Text='<%# Eval("isCorrect") %>' />
</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>
<th style="border-bottom:2px solid #003366; ">is Correct?</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>
<td>
<asp:Label ID="isCorrectLabel" runat="server"
Text='<%# Eval("isCorrect") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
</div>
<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)))"
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" DefaultValue="0"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Again, my problem is having two different tables in the database. The ListView is bound to the Answer table. And for the CheckBox, it has to be bound to the second table which is the QuizContent, so how to do that?
UPDATE:
Here's a snapshot to show you what I am missing in the code:
Modifying the query of the SqlDatasource3 does the trick
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:QuizSysDBConnectionString %>"
SelectCommand="SELECT Answers.*, QuizContent.IsCorrect
FROM Answers INNER JOIN
QuizContent ON Answers.AnswerID = QuizContent.AnswerID
WHERE (QuizContent.QuestionID = #QuestionID)"
Change your sqldatasource3 select statement as
SELECT AnswerID, Answer
FROM Answers
WHERE (AnswerID IN
(SELECT DISTINCT AnswerID
FROM QuizContent
WHERE (QuestionID = #QuestionID)))
UNION ALL
SELECT AnswerID,isCorrect from QuizContent
WHERE Answers.AnswerID = QuizContent.AnswerID

Object Data Source not filtering my listview?

I'm trying to filter a listview, using a textbox control via an object datasource. However when I add anything nothing happens . I've created something similar before and all the codes pretty much the same. anyone got any ideas' what I'm missing ??
<asp:TextBox ID="namefilter" runat="server" />
<asp:Button ID="button1" runat="server" />
<asp:ListView DataSourceID="DataSource" ID="ListView1" runat="server" DataKeyNames="ID" InsertItemPosition="LastItem">
<LayoutTemplate>
<table cellspacing="1" cellpadding="1" border="0" bgcolor="#6699cc" width="100%" >
<tr>
<th> </th>
<th> </th>
<th><span class="Caption1">Name</span></th>
<th><span class="Caption1">Phone</span></th>
</tr>
<tr id="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="background-color: White;" >
<td><asp:LinkButton ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" /></td>
<td><asp:LinkButton ID="btnDelete" runat="server" Text="Delete" CommandName="Delete" /></td>
<td align="center"><%# DataBinder.Eval(Container, "DataItem.Name")%> </td>
<td align="center"><%# DataBinder.Eval(Container, "DataItem.Phone")%> </td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr style="background-color: White;" >
<td><asp:LinkButton ID="btnSave" runat="server" Text="Save" CommandName="Update" /></td>
<td><asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" /></td>
<td><asp:TextBox ID="EditName" runat="server" Text='<%# Bind("Name") %>' /></td>
<td><asp:TextBox ID="EditPhone" runat="server" Text='<%# Bind("Phone") %>' /></td>
</tr>
</EditItemTemplate>
<InsertItemTemplate>
<tr bgcolor="#6699cc" >
<td><asp:LinkButton ID="InsertButton" CommandName="Insert" runat="server" Text="Insert" ValidationGroup="add" CssClass="Caption1" /> </td>
<td><asp:LinkButton ID="CancelButton" CommandName="Cancel" runat="server" Text="Cancel" CausesValidation="false" CssClass="Caption1" /></td>
<td> <asp:TextBox ID="InsertName" runat="server" Text='<%# Bind("Name") %>' ValidationGroup="insert" /> </td>
<td><asp:TextBox ID="InsertPhone" runat="server" Text='<%# Bind("Phone") %>' /> </td>
</InsertItemTemplate>
</asp:ListView>
<asp:LinqDataSource
ContextTypeName="assembly"
EnableUpdate="true"
EnableDelete="true"
EnableInsert="true"
ID="DataSource"
OrderBy="Email desc"
runat="server"
TableName="Contacts"
AutoSort="true"
>
<whereParameters>
<asp:ControlParameter ControlID="emailfilter" Name="Email" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" />
</whereParameters>
</asp:LinqDataSource>
d'oh, forgot to add the sort by where clause in the linqdatasource.. 3 hours wasted!!!
<asp:LinqDataSource
ContextTypeName="Immediacy.VS.Plugins.DBML.VisitScotlandDataContext"
EnableUpdate="true"
EnableDelete="true"
EnableInsert="true"
ID="DataSource"
OrderBy="Email desc"
runat="server"
TableName="Contacts"
AutoSort="true"
Where='(#Email == null) || (Email == #Email)'
>

Categories