【问题标题】:asp.net c# gridview sorting by an AJAX rating controlasp.net c# gridview 按 AJAX 评级控件排序
【发布时间】:2012-11-06 18:00:53
【问题描述】:

我在我的 Gridview 中添加了一个 Ajax 评级控件,如下所示:

  <asp:BoundField DataField="Wrms_QueryId" HeaderText="Warms_QueryId" ReadOnly="True" SortExpression="Wrms_QueryId" />
            <asp:TemplateField HeaderText="Favourites">
                <ItemTemplate>
                    <asp:Rating ID="Rating1" runat="server" AutoPostBack="true"  CurrentRating='<%# Bind("num") %>' MaxRating="3" RatingAlign="Horizontal"
                        RatingDirection="LeftToRightTopToBottom" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar"
                        FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar" Tag='<%# Bind("Wrms_QueryId")%>' OnChanged="Rating1_Changed">
                    </asp:Rating>
                </ItemTemplate>
            </asp:TemplateField>

在.cs中

 protected void Rating1_Changed(object sender, EventArgs e)
{
    Rating ra= (Rating)sender; 
    GridViewRow gr=(GridViewRow) ra.Parent.Parent;          

    // table update required?

    Rating r = sender as Rating;
     int id = Convert.ToInt32(r.Tag);
     int lf = Convert.ToInt32(r.CurrentRating);
     string strSQL2 = "UPDATE [dbo].[wrms_config_m] set QueryId = " + lf + " where  Wrms_QueryId = " + id;
     ExecuteSQLUpdate(strSQL2);


}    

但我不知道如何将排序添加到评分列。通常我只会添加 SortExpression="####" 但这似乎不支持评级列。

我浏览了很多论坛都找不到答案。任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 我对这个控件不熟悉,但是如果你想让网格在变化时重新排序,你不需要重新绑定网格吗?如果“当前评分”绑定到“num”,那么“num”不应该是 BoundColumn 的 SortExpression 吗?
  • 感谢 Ann L。关于重新绑定,您可能是对的,但由于这是一个 Ajax 控件,因此似乎不需要。排序表达式和允许排序属性似乎不受支持或对此控件有任何影响。

标签: c# asp.net ajax gridview


【解决方案1】:

好的,我自己解决了这个问题。我将排序添加到错误的行。需要开启

<asp:TemplateField HeaderText="Favourites" SortExpression="num">

【讨论】:

    猜你喜欢
    • 2016-10-15
    • 2011-09-02
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多