0

NET 与 VB.net。我想对列 dgv 表进行排序,但代码不起作用。

客户端是这样的

 <asp:GridView ID="griddata" runat="server"  AutoGenerateColumns="false" AllowSorting="True" >
                <Columns >
                <asp:TemplateField>
                        <ItemTemplate>
                            <asp:CheckBox ID="chkStatus" runat="server"  />
                            <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# eval("ID") %>' />
                        </ItemTemplate>                   
                </asp:TemplateField>

                <asp:BoundField DataField="First_Name" HeaderText="First Name" SortExpression="First_Name"/>
                <asp:BoundField DataField="Last_Name" HeaderText="Last Name" SortExpression="Last_Name" />
                <asp:BoundField DataField="Address" HeaderText="Address" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" />
            </Columns>        
        </asp:GridView>

服务器端是这样的

Imports System.Data.SqlClient
Imports System.Configuration
Imports System.IO

Partial Public Class Course
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        listhendle()

    End Sub

    Protected Sub listhendle()
        Dim ds As New DataSet
        Dim cls As New connections

        ds = cls.returndataset("select * from [m.student] ")

        GridView1.DataSource = ds
        GridView1.DataBind()

    End Sub


End Class

我错过了什么吗?我从这里得到了参考,我改变了数据连接

4

2 回答 2

0

没有代码隐藏

你可以做一件事......做数据库连接@codebehind并在aspx文件中复制以下代码并重命名它......

它会工作...

于 2012-07-23T10:32:36.490 回答
0

在 aspx 中:设置allowsorting = true

在 C# 中:

protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
    {
        DataTable dataTable = gvEmployeeList .DataSource as DataTable;
        DataTable dtEmplist = new DataTable();
        dtEmplist = iz.getEmployeeList();
        if (dtEmplist.Rows.Count > 0 )
        {
            DataView dataView = new DataView(dtEmplist);
            dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

            gvEmployeeList.DataSource = dataView;
            gvEmployeeList.DataBind();
        }
    }
于 2012-07-23T10:37:21.280 回答