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# 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
Hope this helps if yes the accept and vote the answer otherwise revert back with your queries
--Rahul D.