0

对,好吧,我在他的第 9 部分等博客中遵循了 Scott Gu 的示例,尽管我尽最大努力实现“自动排序、分页和编辑”,但我无法让某某工作。

是否可以通过以下设置进行自动排序、分页和编辑?

<asp:TextBox ID="tbxHowMany" runat="server"></asp:TextBox>

    <asp:RadioButtonList ID="radMaterial" runat="server">
        <asp:ListItem>Paper</asp:ListItem>
        <asp:ListItem>Glass</asp:ListItem>
    </asp:RadioButtonList>


    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />


    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" 
        DataSourceID="LQTOPDS" Font-Size="XX-Small" ForeColor="#333333" 
        GridLines="None" DataKeyNames="PriKey" 
        AllowPaging="True" AllowSorting="True">
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:BoundField DataField="Productpriority" HeaderText="Productpriority" 
                SortExpression="Productpriority" />
            <asp:BoundField DataField="MemberId" HeaderText="MemberId" 
                SortExpression="MemberId" />
            <asp:BoundField DataField="UnitWeight" HeaderText="UnitWeight" 
                SortExpression="UnitWeight" />
            <asp:BoundField DataField="WeightUnitCode" HeaderText="WeightUnitCode" 
                SortExpression="WeightUnitCode" />
            <asp:BoundField DataField="RecycledContent" HeaderText="RecycledContent" 
                SortExpression="RecycledContent" />
            <asp:BoundField DataField="IsBiodegradable" HeaderText="IsBiodegradable" 
                SortExpression="IsBiodegradable" />
            <asp:BoundField DataField="Recyclability" HeaderText="Recyclability" 
                SortExpression="Recyclability" />
            <asp:BoundField DataField="RevisionSourceCode" HeaderText="RevisionSourceCode" 
                SortExpression="RevisionSourceCode" />
            <asp:BoundField DataField="PriKey" HeaderText="PriKey" 
                SortExpression="PriKey" ReadOnly="True" />
        </Columns>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>

    <asp:LinqDataSource ID="LQTOPDS" runat="server" 
        ContextTypeName="LQTOPDSDataContext" EnableInsert="True" EnableUpdate="True" 
        TableName="tblOnlineReportingCOMPLETEWEIGHTSFINALs" 
        Where="MaterialText == @MaterialText &amp;&amp; Productpriority &lt;= @Productpriority">

        <WhereParameters>
            <asp:ControlParameter ControlID="radMaterial" Name="MaterialText" 
                PropertyName="SelectedValue" Type="String" />
            <asp:ControlParameter ControlID="tbxHowMany" Name="Productpriority" 
                PropertyName="Text" Type="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>

目前我唯一的代码如下:

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.DataSourceID = null;

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        GridView1.DataSourceID = "LQTOPDS";
            GridView1.DataBind();
    }

}

这让我发疯......我读到这个排序/分页/编辑功能应该是自动的,但显然我做错了什么。

如果有人可以向我解释为什么没有生成此功能,我将不胜感激。

4

1 回答 1

1

这最终是通过更改创建数据来源的表的方法来实现的。

我删除了本质上用作 where 子句的“SELECT TOP”,并使用了不同的方法。我对数据进行了排名并使用了“获取”——这有效地选择了预先排序的数据,从而消除了任何导致 gridview 分页、排序等问题的附加选择。

如果有人想查看代码,请告诉我。

于 2010-01-13T14:56:27.017 回答