Display multiple datas from same table from mysql using listview - asp.net

I am using a listview to display datas from 3 tables in mysql.
My tables are,
theatredet(theaterid,theatername,locationid)
location(locationid,locationname)
screendet(screenname,theaterid,seatsavailable)
I want to display datas from screendet on the basis of theaterid from the table theatredet,i can only able to disply single data from screendet,there are multiple datas on that table with respect of theaterid.
My query is,
string query = "SELECT `theatredetails`.*,`Location`.`LocationName`,
`screendetails`.`ScreenName`,`screendetails`.`SeatsAvailable`
FROM `theatredetails`INNER JOIN `screendetails`
ON `screendetails`.`TheatreDetailsId` = `theatredetails`.`TheatreDetailsId`
INNER JOIN `location` ON `location`.`LocationId`=`theatredetails`.`LocationId`;";
My aspx
<asp:TextBox ID="TextBox6" runat="server" Text='<%#Bind("ScreenName") %>'></asp:TextBox>
<asp:TextBox ID="TextBox7" runat="server" Text='<%#Bind("SeatsAvailable") %>'></asp:TextBox>

Assuming you have already tested your query on MySql and it is returning intended number of rows.
You can populate your listview using the following code (I am using SqlDataSource to bind the ListView, you can use any other method)
<asp:ListView ID="lstviewScreens" runat="server" DataSourceID="ScreensSqlDataSource" >
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" >
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr style="background-color: #E0FFFF;">
<td>
<strong>Theater Name:</strong><asp:Label ID="lblTheaterName" runat="server" Text='<%# Eval("theatername") %>' />
<br />
<strong>Screen Name:</strong><asp:Label ID="lblScreenName" runat="server" Text='<%# Eval("ScreenName") %>' />
<br />
<strong>Seats Available</strong><asp:Label ID="lblSeatsAvailable" runat="server" Text='<%# Eval("SeatsAvailable") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="ScreensSqlDataSource" runat="server"
ConnectionString="Your connection String"
SelectCommand="SELECT theatredetails.*,Location.LocationName,
screendetails.ScreenName,screendetails.SeatsAvailable
FROM theatredetails INNER JOIN screendetails
ON screendetails.TheatreDetailsId = theatredetails.TheatreDetailsId
INNER JOIN location ON location.LocationId=theatredetails.LocationId">
</asp:SqlDataSource>
This will output your data in tabular format, however you can customize LayoutTemplate to change the generated html, even you can use GroupTemplate to group the data.

Related

My query works in Access, but not in Visual Studio [duplicate]

This question already has an answer here:
Query returns no records to show on my webpage
(1 answer)
Closed 9 years ago.
I have a query that I have run in Access that doesn't seem to run when I execute it on my website site. Here's the code for the webpage that I want the database to populate content for:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/TravelJoansDB.accdb"
SelectCommand="SELECT * FROM [Table2] INNER JOIN BlogEntryItems ON Table2.ID=BlogEntryItems.BlogID AND Table2.ID=#ID">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="Table2.ID" Type="Decimal" />
</SelectParameters>
</asp:AccessDataSource>
<asp:DataList ID="DataList1" DataSourceID="AccessDataSource1"
runat="server" ItemStyle-CssClass="picTableStyle"
DataKeyField="Table.2ID">
<ItemStyle></ItemStyle>
<ItemTemplate>
<table>
<tr>
<td>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "PlaceImages/" + Eval("Image") %>' /><br />
<asp:Label ID="Label1" CssClass="picCaptionStyle" runat="server" Text='<%# Eval("Caption") %>' />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" class="picBodyText" runat="server" Text='<%# Eval("PicStory") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
When I take out the join, it works fine. I add the join and it doesn't give me any error or anything, it just seems as though there are no results for it to show on my website. Any ideas?
Note that I haven't worked on AccessDataSource. However, looking at the docs - here is what you should look into
Change the query to use ? instead of #ID
SelectCommand="SELECT * FROM [Table2] INNER JOIN BlogEntryItems ON Table2.ID=BlogEntryItems.BlogID AND Table2.ID= ?"
Because the AccessDataSource control extends the SqlDataSource class
and uses the System.Data.OleDb provider, you specify parameter
placeholders using the "?" placeholder character.
ref: http://msdn.microsoft.com/en-us/library/8e5545e1%28v=vs.100%29.aspx
If the above doesn't work, omit the data type (Decimal) of the parameter OR specify a relevant type such as Integer instead.

How can I add and delete row on Telerik's RadListBox Control?

I'm using Telerik's RadListBox control for my web application development, wondering how can I add row into RadListBox via TextBox control, below is my code fragment:
<telerik:RadListBox ID="rlbControl" runat="server" SelectionMode="Multiple">
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' ></asp:Label>
</td>
<td style="width:20px"></td>
<td >
<asp:Label ID="lblAge" runat="server" Text='<%# Eval("Age") %>' ></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadListBox>
Name : <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
Age : <asp:TextBox ID="txtAge" runat="server" ></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
<asp:Button ID="btnDel" runat="server" Text="Delete" OnClick="btnDel_Click"/>
When Add button click, get input from two TextBox and bind into RadListBox.
For deleting, select row from RadListBox and click on Delete button, remove the selected row from the RadListBox.
My question is how can I add and delete rows?
Thank you in advanced.
Hi you can create datatable and datarows. then add the textbox values to dararow. then u can bind this datatable to the RadListBox. For deleting, u need to pick the ListItem index and delete the row from the datatable and again bind to the RadListBox. It will work..
Link for delete Row demo
Also check with my answer in the below link post. you will get idea about insert row
Add rows to ListView

Creating posts and comments similar to Facebook

I need my own posts and comment on the page in my project, something similar to Facebook. I succesfully created posts by using sql table, sqldatasource and repeater. But I have a problem with comments.
I created sql table Comments, there is a column with Post ID. This is my code:
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:MotWebConnectionString %>"
SelectCommand="SELECT * FROM [Posts]
JOIN [Users] ON [Users].[UserName] = [Posts].[UserName]
JOIN [Comments] ON [Comments].[PostId] = [Posts].[PostId]
WHERE ([GroupId] = #GroupId) ">
<SelectParameters>
<asp:QueryStringParameter Name="GroupId" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource3" >
<ItemTemplate>
<table style="width: 100%;">
<tr>
<td width="10%">
<asp:Image ID="Image2" runat="server" Width="64px" Height="64px" ImageUrl='<%# Eval("ProfilePicture")%>' />
</td>
<td align="left" width="90%" >
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("UserName", "~/_/Profile.aspx?Username={0}")%>'><p><asp:Literal ID="Literal2" runat="server" Text='<%# Eval("Username")%>'></asp:Literal></p></asp:HyperLink>
</td>
</tr>
</table>
<asp:Literal ID="Literal3" runat="server" Text='<%# Eval("Text")%>'></asp:Literal>
<br />
<asp:Literal ID="Literal4" runat="server" Text='<%# Eval("CommentText")%>'></asp:Literal>
<asp:FormView ID="FormView2" runat="server" DataSourceID="SqlDataSource4" DefaultMode="Insert" >
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" CommandName="Insert" />
</InsertItemTemplate>
</asp:FormView>
</ItemTemplate>
<SeparatorTemplate>
<br />
<br />
<br />
</SeparatorTemplate>
</asp:Repeater>
But it shows only posts, where is at least 1 comment and if there are more comments than 1, the posts is twice or more times on the page.
And another problem is, that I don't know how to insert right Post ID into the Comments table. It is probably by using Parameter...
My database schema (I did't know how to create it in SQL Management Studio, so it is in VS):
http://img685.imageshack.us/img685/1416/vstiekd.jpg
Please could anyone help me with this:
How to view right comments under the post and view also posts without any comment
How to insert the comment with right Post ID
I will be very thankfull for any kind of help

ListView InsertItemTemplate Does not work

I can't get <%# Eval("ID") %> work, although it works outside of the InserItemTemplate. What is worng?
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="btnInsert" runat="server" CommandName="InsertPhone" CommandArgument='<%# Eval("ID") %>' Text="InsertPhone" />
</td>
<td style="width:50px">
<asp:DropDownList runat="server" ID="ddlPhoneType" DataSourceID='ObjectDataSourcePhoneTypes'
DataTextField="Name_ar" DataValueField="ID" />
</td>
<td style="width:100px">
<asp:TextBox ID="PhoneNumberLabel" runat="server" Text='' />
</td>
</tr>
</InsertItemTemplate>
Thanks
Insert template isn't data bound so you can't use Eval there... Eval works in the context of a data bound row, but insert row is not data bound, so there's no data source for it. Programmably set the value in the field if you need to establish some value for a control.

ASP.NET Repeater will not show data

I have an ASP.Net Repeater I want to use to show From and Text from a dataset and I want to add it programmically. I have all the data in a dataset and can use that and I have verified the correct number for datarows when it loads so the data is their it is just not showing. What have I missed?.
Dim data As New Data
Dim ds As New DataSet
ds = data.LOADALL()
Dim drMsg() As DataRow = ds.Tables("MESSAGESYSTEM").Select("TOID='101'")
repeatMessages.DatagSource = drMsg
Now on the html side I have:
<asp:Repeater ID="repeatMessages" runat="server" >
<HeaderTemplate>
<table>
<tr>
<th>From</th>
<th>Sublect</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td bgcolor="#CCFFCC">
<asp:Label runat="server" ID="Label1" text='<%# Eval("FROMID") %>' />
</td>
<td bgcolor="#CCFFCC">
<asp:Label runat="server" ID="Label2" text='<%# Eval("MESSAGETEXT") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
How can I fix this code to show the data in the Message table?
Try calling repeatMessages.DataBind(). All you are doing is assigning the source but you haven't told the program to do something with the data.

Resources