Thanks melvik & alyeng2000
But i m getting error
AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when AllowPaging is set to true and the selected datasource does not implement ICollection.
HERE IS MY CODE
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using DriveConnection;
namespace DRIVE.Test
{
/// <summary>
/// Summary description for TestDG.
/// </summary>
public class TestDG : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
string SortField;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
//SortField = "vchrQuarterID";
if (SortField == null)
{
SortField = "intSegmentProposalID";
}
BindGrid();
}
}
void BindGrid()
{
DBConn cn = new DBConn();
SqlConnection cnn = cn.openConnection();
string strText;
strText = "Myprocedure '" + SortField + "'";
SqlCommand cmd = new SqlCommand(strText,cnn);
SqlDataReader drSegRpt = cmd.ExecuteReader();
//DataGrid1.DataSource = drSegRpt;
//DataGrid1.DataBind();
drSegRpt.Close();
SqlCommand cmd1 = new SqlCommand(strText,cnn);
SqlDataReader drSegRpt1 = cmd1.ExecuteReader();
DataGrid1.DataSource = drSegRpt1;
DataGrid1.DataBind();
}
private void DataGrid1_Sort(object source, System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
SortField = (string)e.SortExpression;
BindGrid();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEvent Handler(this.DataGrid1_Sort);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexCh anged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
=================
<%@ Page language="c#" Codebehind="TestDG.aspx.cs" AutoEventWireup="false" Inherits="DRIVE.Test.TestDG" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>TestDG</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
AllowSorting="True" BorderColor="Silver" Font-Names="Verdana" Font-Size="Smaller" AutoGenerateColumns="False"
AllowPaging="True">
<HeaderStyle Font-Size="Smaller" Font-Names="Verdana" Font-Bold="True" BackColor="Silver"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="vchrQuarterId" SortExpression="vchrQuarterId" HeaderText="Fiscal Quarter"></asp:BoundColumn>
<asp:BoundColumn DataField="vchrVendorName" SortExpression="vchrVendorName" HeaderText="Vendor"></asp:BoundColumn>
</Columns>
</asp:datagrid>
</form>
</body>
</HTML>
|