本文介绍了如何使用列名对网格视图进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我想通过对列'mem_id'进行排序来显示gridview。下面是我的代码:



In my project I would like to display the gridview by sorting the column 'mem_id'. Hereunder is my code:

<asp:GridView ID="GridView2" runat="server"  HorizontalAlign="Center"  AutoGenerateColumns="False"   AllowSorting="true"

            PageSize="12" onpageindexchanging="GridView2_PageIndexChanging" style="border-color: #808000; font-size:small; top: 176px; left: 27px; position: absolute; height: 75px; width:1350px" >
            <RowStyle HorizontalAlign="Center" />
            <Columns >
            <asp:BoundField DataField="mem_id" HeaderText="Mem_ID"/>
            <asp:BoundField DataField="mem_name" HeaderText="Mem Name"/>
            <asp:BoundField DataField="mobile" HeaderText="Cell No:"/>
            </Columns>
            </asp:GridView>







任何人都可以指导我如何对mem_id列进行排序。

问候。




Can anyone guide me how to sort on mem_id column.
Regards.

推荐答案

<asp:gridview id="gvOutlookMeldingen" runat="server" xmlns:asp="#unknown">
        AllowSorting="True" 
        OnSorting="gvOutlookMeldingen_Sorting"
        AutoGenerateColumns="False" 
        AutoGenerateSelectButton="True" 
        onselectedindexchanged="GridView_SelectedIndexChanged">
        <columns>
            <asp:boundfield datafield="Melder" headertext="Melder" sortexpression="Melder" />
            <asp:boundfield datafield="Onderwerp" headertext="Onderwerp" sortexpression="Onderwerp" />
            <asp:templatefield headertext="Omschrijving" sortexpression="Omschrijving">
                <itemtemplate>
                    <div style="overflow:auto; width: 500px; height: 200px;">
                        <asp:label id="lblOmschrijving" runat="server" text="<%# Bind("Omschrijving")%>"></asp:label>
                    </div>
                </itemtemplate>
            </asp:templatefield>
            <asp:boundfield datafield="Meldingsdatum" headertext="Meldingsdatum" sortexpression="Meldingsdatum" />
            <asp:boundfield datafield="OutlookID" headertext="OutlookID" sortexpression="OutlookID" />
        </columns>
    </asp:gridview>



从代码behing到这个...


And from to the code behing put this...

protected void gvOutlookMeldingen_Sorting(object sender, GridViewSortEventArgs e)
        {
            switch (e.SortExpression)
            {
                case "Melder":
                    if (e.SortDirection == SortDirection.Ascending)
                    {
                        gvOutlookMeldingen.DataSource = // Asc query for Melder field;
                        gvOutlookMeldingen.DataBind();
                    }
                    else
                    {
                        gvOutlookMeldingen.DataSource = // Desc query for Melder field ;
                        gvOutlookMeldingen.DataBind();
                    }

                    break;

                // case statements for your other fields.
            }
        }


这篇关于如何使用列名对网格视图进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 01:06