GridView, SortedAscendingCellStyle服务器端绑定



我尝试使用SortedAscendingCellStyle来分配我的gridView的样式,这是我的ASP代码:

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" CellPadding="4" OnSorting="GridView1_Sorting" AutoGenerateColumns="false">
            <SortedAscendingCellStyle CssClass="SortedAscendingCellStyle" />
            <SortedAscendingHeaderStyle CssClass="SortedAscendingHeaderStyle" />
            <SortedDescendingCellStyle CssClass="SortedDescendingCellStyle" />
            <SortedDescendingHeaderStyle CssClass="SortedDescendingHeaderStyle " />
            <Columns>
                <asp:BoundField DataField="Nom" HeaderText="Nom" SortExpression="NOM">
                    <ItemStyle Width="150px" />
                </asp:BoundField>
                <asp:BoundField DataField="Prenom" HeaderText="Prenom">
                    <ItemStyle Width="150px" />
                </asp:BoundField>
                <asp:BoundField DataField="Pseudo" HeaderText="Pseudo"></asp:BoundField>
                <asp:BoundField DataField="Mail" HeaderText="Mail">
                    <ItemStyle Width="140px" />
                </asp:BoundField>
            </Columns>
        </asp:GridView>

没有问题,当我使用DataSourceID,但当我使用服务器端数据库SortedAscendingCellStyle没有工作,这是我的代码后面:

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                EmployeDAL oem = new EmployeDAL();
                this.GridView1.DataSource = oem.GetAll();
                GridView1.DataBind();
            }
        }

从我的研究看来,你不能使用这些很好的属性你手动绑定你的GridView在代码背后。你可以在这里找到关于这个话题的另一个讨论:

http://forums.asp.net/t/1725183.aspx/1

…还有这里…

http://www.aarongoldenthal.com/post/2009/04/19/Manually-Databinding-a-GridView.aspx

祝你好运!

最新更新