是否可以在列的网格视图中进行分页 [英] is it possible to give paging in grid view on columns

查看:40
本文介绍了是否可以在列的网格视图中进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在在线帐户系统的应用中,网格视图包含大约70列.
但我想一次只说7列.可能吗?如果是,那么怎么办?

In application of on line accounts systems, a grid view contains around 70 columns.
But I want to show say only 7 columns at a time. Is it possible? If yes, then how?

推荐答案

提供电子表格进行下载会更好吗?

您可以将网格放置在设置了溢出的div中,以便可以滚动.或者,提供列分页按钮,这些按钮将导致用下一组列来绘制网格.我可以想到的几种方法.一种,查询数据源,仅返回选定的列,然后将其绑定到网格.第二,在查询必要的列之后过滤数据源.第三,每次手动创建网格列.
Wouldn''t it be better to give a spreadsheet for download?

You could place the grid in a div with the overflows set so it would be scrollable. Or, provide column paging buttons that would cause the grid to be drawn with the next set of columns. A couple of ways for this that I can think of. One, query the datasource and only return the selected columns then bind it to the grid. Two, filter the datasource after querying for the necessary columns. Three, manually create the grid columns each time.


以下是您可以找到解决方法的代码

Aspx代码

Here is code through which you will find workaround

Aspx code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CP_325671_is_it_possible_to_give_paging_in_grid_view_on_colu._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
        <asp:Button ID="Button1" runat="server" Text="Page1" onclick="Button1_Click" />
        <asp:Button ID="Button2" runat="server" Text="Page2" onclick="Button2_Click" />
        <asp:Button ID="Button3" runat="server" Text="Page3" onclick="Button3_Click" />

    </div>
    </form>
</body>
</html>



C#代码



C# Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace CP_325671_is_it_possible_to_give_paging_in_grid_view_on_colu
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


            
     

            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string myConnection = "Data Source=MDT765;Initial Catalog=TST;User Id=sa;Password=sa@123;";
            string sqlquery;
            sqlquery = "EXEC FindTable " + 1;
            SqlDataAdapter sqlcom0 = new SqlDataAdapter(sqlquery, myConnection);

            DataSet ds0 = new DataSet();
            sqlcom0.Fill(ds0);
            GridView1.DataSource = ds0.Tables[0].DefaultView;
            GridView1.DataBind();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string myConnection = "Data Source=MDT765;Initial Catalog=TST;User Id=sa;Password=sa@123;";
            string sqlquery;
            sqlquery = "EXEC FindTable " + 2;
            SqlDataAdapter sqlcom0 = new SqlDataAdapter(sqlquery, myConnection);

            DataSet ds0 = new DataSet();
            sqlcom0.Fill(ds0);
            GridView1.DataSource = ds0.Tables[0].DefaultView;
            GridView1.DataBind();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            string myConnection = "Data Source=MDT765;Initial Catalog=TST;User Id=sa;Password=sa@123;";
            string sqlquery;
            sqlquery = "EXEC FindTable " + 3;
            SqlDataAdapter sqlcom0 = new SqlDataAdapter(sqlquery, myConnection);

            DataSet ds0 = new DataSet();
            sqlcom0.Fill(ds0);
            GridView1.DataSource = ds0.Tables[0].DefaultView;
            GridView1.DataBind();
        }
    }
}




存储过程





Stored Procedure


CREATE PROCEDURE [dbo].[FindTable]
     @Page BIGINT
AS
BEGIN
  IF @Page = 1
            SELECT [Column1],[Column2],[Column3] FROM [Table1]
          IF @Page = 2
            SELECT [Column4],[Column5],[Column6] FROM [Table1]
          IF @Page = 3
             SELECT [Column7],[Column8] FROM [Table1]
END

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON


GO




希望这可以帮助(如果是)接受并投票回答答案,否则返回您的查询
--Rahul D.




Hope this helps if yes the accept and vote the answer otherwise revert back with your queries
--Rahul D.


是的,但是您需要将其实现为自定义解决方案.
首先,我想到的是定义带有隐藏在开始位置的所有可用列的gridview.
然后,您需要制作"column pager"(可以是网格页脚中或网格下方的一些超链接控件),1-7、8-14、15-21等,直到70.
然后,当您绑定网格时,将根据选定的"pager"值将其绑定.这意味着您将需要隐藏所有超出选定范围的其他列...
使用这种和平的代码来隐藏列...
Yes it is, but you need to implement that as custom solution.
First what gets on my mind is to define gridview with all available columns which are hidden in start.
Then you need to make "column pager" (this can be a few hyperlinks controls in your grid footer or below grid), 1-7, 8-14, 15-21 and so on until 70.
Then when you bind grid you will bind it according to selected "pager" value. this means that you will need to hide all other columns that are out of selected range...
use this peace of code to hide columns...
gvReport.Columns[1].Visible = false;
gvReport.Columns[2].Visible = false;
gvReport.Columns[3].Visible = false;
gvReport.Columns[4].Visible = false;
gvReport.Columns[5].Visible = false;
gvReport.Columns[6].Visible = false;
gvReport.Columns[7].Visible = false;


等等...我想你可以想像我想说的...

另一种方法是显示可用于某些List(CheckedListBox或某些其他控件)的所有列,并允许用户选择要使用的列.类似于 [ ^ ].

但是毕竟,如果您需要防弹解决方案,请找到一些可以动态显示或隐藏列的第三方网格控件.这里是一些:
1. http://demos.devexpress.com/aspxgridviewdemos/Columns/CustomizationWindow.aspx [ ^ ]
2. http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/headercontextmenu/defaultcs.aspx [ ^ ]


and so on... I guess you can imagine what I want to say...

Another approach is to show all columns available with some List (CheckedListBox or some other control) and alow user to choose what columns he wants to use. Something like this[^].

But after all if you need bullet proof solution find some third party grid control that can show or hide columns dynamically. Here are some:
1. http://demos.devexpress.com/aspxgridviewdemos/Columns/CustomizationWindow.aspx[^]
2. http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/headercontextmenu/defaultcs.aspx[^]


这篇关于是否可以在列的网格视图中进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆