Gridview没有在asp中对excel表进行排序和分页

时间:2016-12-01 06:36:05

标签: c# asp.net visual-studio sorting paging

我有一个gridview,它正在从excel表中获取数据。在visual studio中,我从gridview的属性菜单中启用了分页和排序功能。但这不起作用。是关于excel源还是我应该添加一些额外的代码?

 string whereClause = SearchTextBox.Text;
        String name = "Sheet0";
        String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                        "C:\\Users\\BerkayS\\Desktop\\VSCLOGN.xls" +
                        ";Extended Properties='Excel 12.0 XML;HDR=YES;';";





        OleDbConnection con = new OleDbConnection(constr);
        OleDbCommand oconn = new OleDbCommand("Select " + selectedCriteria + " From [" + name + "$] where USER_ID = '" + whereClause + "'", con);
        con.Open();

        OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
        DataTable data = new DataTable();
        sda.Fill(data);
        GridView2.DataSource = data;
        GridView2.DataBind();


        GridView2.Visible = true;

注意:忽略代码中的一些变量名称,它们在

之前分配

0 个答案:

没有答案