Take a look @
http://www.aspfree.com/examples/504,1/examples.aspx
or You can try out
<p align ="center">
<asp
ataGrid id="DataGrid1" runat="server" BorderColor="#E7E7FF"
AllowPaging="True" OnPageIndexChanged="PageRecords" PageSize=<%#intPageSize%>
BorderWidth="1px" BackColor="White" CellPadding="3"
GridLines="Horizontal" BorderStyle="None" Font-Names="Verdana"
Font-Size="X-Small" Width="50%" ItemStyle-Width="25%">
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
<PagerStyle Visible="true" HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF"
Mode="NumericPages">
</PagerStyle>
</asp
ataGrid>
</p>
SqlConnection mycn;
SqlDataAdapter myda;
DataSet ds;
String strConn;
protected int intPageSize;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
strConn="Data Source=localhost;uid=sa;pwd=;Initial Catalog=pubs";
mycn = new SqlConnection(strConn);
myda = new SqlDataAdapter ("Select * FROM titles", mycn);
ds= new DataSet ();
myda.Fill (ds,"Table");
//The data is displayed as
//Column1 -> ColumnNames
//Column2 -> Column Data
//Hence the intPageSize is set to number of Columns to be Displayed on page
intPageSize = ds.Tables [0].Columns.Count;
//GoDoReshape(ds)-> Function: To display the data vertically
DataGrid1.DataSource=GoDoReShape(ds);
if (!Page.IsPostBack )
{
DataGrid1.DataBind ();
}
}
public DataSet GoDoReShape(DataSet ds)
{
DataSet NewDs=new DataSet();
NewDs.Tables.Add();
//Create Two Columns with names "ColumnName" and "Value"
//ColumnName -> Displays all ColumnNames
//Value -> Displays ColumnData
NewDs.Tables[0].Columns.Add("ColumnName");
NewDs.Tables[0].Columns.Add("Value");
foreach(DataRow dr in ds.Tables [0].Rows )
{
foreach(System.Data.DataColumn dcol in ds.Tables[0].Columns)
{
//Declare Array
string[] MyArray={dcol.ColumnName.ToString(),dr[dcol.ColumnName.ToString()].ToString()};
NewDs.Tables[0].Rows.Add(MyArray);
}
}
return NewDs;
}
protected void PageRecords(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}
HTH
Regards
Sushila
..NET MVP