2015-09-29 38 views
0

我正在使用一個列表視圖來顯示mysql中的3個表中的數據。 我的表是,使用列表視圖從同一個表中顯示多個數據

theatredet(theaterid,theatername,locationid) 
location(locationid,locationname) 
screendet(screenname,theaterid,seatsavailable) 

我想從表theatredet theaterid的基礎上顯示來自screendet DATAS,我只能能夠DISPLY從screendet單一的數據,有該表上的多個DATAS與尊重theaterid。

我的查詢,

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`;"; 

我的aspx

<asp:TextBox ID="TextBox6" runat="server" Text='<%#Bind("ScreenName") %>'></asp:TextBox> 
<asp:TextBox ID="TextBox7" runat="server" Text='<%#Bind("SeatsAvailable") %>'></asp:TextBox> 
+0

爲什麼在查詢中需要locationId?可能是導致問題的原因 – shreesha

回答

0

假設您已經測試了您的查詢的MySQL和它返回行的預計數量。

您可以用下面的代碼填充您的ListView(我用的SqlDataSource到ListView綁定,您可以用任何其他方法)

<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> 

這將輸出以表格格式的數據,但是你可以自定義LayoutTemplate來更改生成的html,即使您可以使用GroupTemplate對數據進行分組。

相關問題