简体   繁体   English

C#中的下拉列表不包含列

[英]dropdown list in c# does not contain column

i have attatched a database to ac# application. 我已经为ac#应用程序安装了一个数据库。 i have three tables: movie (mid,title,director,year) reviewed(mid,rid,ratingDate, stars) and reviewer( rid, name). 我有三个表:电影(中,职称,导演,年),评论(中,rid,ratingDate,星星)和评论者(中,姓名)。 i want the drop down list to show only the year of the ratingDate that are in the column ( avoid null years). 我希望下拉列表仅显示该列中的ratingDate年份(避免为空年份)。 i then want the selected value to be sent to a grid view to display the movie title and avg rating in order of highest rating in the selected review year. 然后,我希望将所选值发送到网格视图,以按所选评论年度中最高评分的顺序显示电影标题和平均评分。 everytime i run it it says system.data.dataRowView does not contain ratingDate. 每次我运行它时,它都说system.data.dataRowView不包含ratingDate。

here is what i have coded: 这是我编写的代码:

--data source for drop down list -下拉列表的数据源

<asp:SqlDataSource ID="yearsreviewed" runat="server" 
   ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
   SelectCommand="SELECT DISTINCT Year(ratingDate) FROM rating">
</asp:SqlDataSource>

--dropdownlist - 下拉列表

<asp:DropDownList ID="ddlYear" runat="server" 
   DataSourceID="yearsreviewed" DataTextField="ratingDate" 
   DataValueField="ratingDate" AutoPostBack="True">
</asp:DropDownList>

--datasource for gridview --gridview的数据源

<asp:SqlDataSource ID="bestmovie" runat="server" ConnectionString="<%$       ConnectionStrings:ConnectionString %>" 
   SelectCommand="SELECT movie.title, AVG(rating.stars) AS newRating, rating.ratingDate FROM movie INNER JOIN rating ON movie.mid = rating.mid WHERE (rating.ratingDate IS NOT NULL) AND (YEAR(rating.ratingDate) = @ratingDate) GROUP BY rating.ratingDate, movie.title ORDER BY rating.ratingDate, newRating DESC">
   <SelectParameters>
      <asp:ControlParameter ControlID="ddlYear" Name="ratingDate" PropertyName="SelectedValue" />
   </SelectParameters>
</asp:SqlDataSource>`

--gridView - 网格视图

<asp:GridView ID="gvBestMovie" runat="server" AutoGenerateColumns="False" 
   CellPadding="4" DataSourceID="bestmovie" ForeColor="#333333" 
   GridLines="None">
   <AlternatingRowStyle BackColor="White" />
      <Columns>
         <asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
         <asp:BoundField DataField="newRating" HeaderText="newRating" ReadOnly="True" 
                SortExpression="newRating" />
         <asp:BoundField DataField="ratingDate" HeaderText="ratingDate" 
                SortExpression="ratingDate" />
      </Columns>
      <EditRowStyle BackColor="#7C6F57" />
      <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
      <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
      <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
      <RowStyle BackColor="#E3EAEB" />
      <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
      <SortedAscendingCellStyle BackColor="#F8FAFA" />
      <SortedAscendingHeaderStyle BackColor="#246B61" />
      <SortedDescendingCellStyle BackColor="#D4DFE1" />
      <SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>

i have done almost the exact same thing with a different query and it works great. 我已经用不同的查询做了几乎完全相同的事情,并且效果很好。 please help i dont know what im missing 请帮助我不知道我在想什么

在yearsreviewed数据源中,您是否尝试过在select语句中使用别名?

SELECT DISTINCT Year(ratingDate) as ratingDate FROM rating

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM