473,811 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid Paging with AutoGenerateCol umns part 2

Just in case anyone else out there is having the same problem of the
page numbers appearing in one column instead of across the row, here's
how to fix the problem courtesy of swn...@gmail.co m from his original
thread of this subject.

Below are the C# and VB.NET code samples of the prerender event of the
datagrid:
C#:

protected void dGrid_PreRender (object sender, EventArgs e)
{
try
{
DataGrid dg = (DataGrid)sende r;
//Fix for numbering being in a left aligned column
//For some reason, the ColumnSpan property is ignored and
not rendered
//unless set using the Attributes
if (dg.AllowPaging == true && dg.AutoGenerate Columns ==
true)
{
//Get the Table
System.Web.UI.W ebControls.Tabl e tab =
(System.Web.UI. WebControls.Tab le)dg.Controls[0];
//Change the Top Pager
if (dg.PagerStyle. Position == PagerPosition.B ottom ||
dg.PagerStyle.P osition == PagerPosition.T opAndBottom)
{
tab.Rows[tab.Rows.Count -
1].Cells[0].Attributes.Add ("colspan",
tab.Rows[1].Cells.Count.To String());
}
//Change the Bottom Pager
if (dg.PagerStyle. Position == PagerPosition.T op ||
dg.PagerStyle.P osition == PagerPosition.T opAndBottom)
{
tab.Rows[0].Cells[0].Attributes.Add ("colspan",
tab.Rows[1].Cells.Count.To String());
}
}
}
catch (Exception ex)
{

}
}

VB.NET:

Private Sub myDatagrid_PreR ender(ByVal sender As Object, ByVal e
As System.EventArg s) Handles myDatagrid.PreR ender
'Fix for page numbers appearing in one column and expanding
it
'making the datagrid look ugly.

Dim dg As DataGrid = sender

If dg.AllowPaging = True And dg.AutoGenerate Columns = True
Then

'Get the Table
Dim tab As System.Web.UI.W ebControls.Tabl e =
dg.Controls(0)
'Change the Top Pager
If dg.PagerStyle.P osition = PagerPosition.B ottom Or
dg.PagerStyle.P osition = PagerPosition.T opAndBottom Then

tab.Rows(tab.Ro ws.Count -
1).Cells(0).Att ributes.Add("co lspan",
tab.Rows(1).Cel ls.Count.ToStri ng())

'Change the Bottom Pager
If (dg.PagerStyle. Position = PagerPosition.T op Or
dg.PagerStyle.P osition = PagerPosition.T opAndBottom) Then

tab.Rows(0).Cel ls(0).Attribute s.Add("colspan" ,
tab.Rows(1).Cel ls.Count.ToStri ng())
End If
End If
End If
End Sub

Apr 11 '07 #1
0 2514

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2264
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at the bottom of the dg.) When I click on the pages nothing happens until I get to the last page. Then and only then is the last page displayed. If I go back through the pages the second to last page displayes the first page again.
3
1753
by: DC | last post by:
Dear ASP.Net Experts, In ASP, I can write something like this: <table> <tr> <th align=left>ID</th> <th align=left>Product Name</th> <th align=left>Price</th> </tr> <%
1
4163
by: iforsyth | last post by:
Have a paging datagrid with a checkbox control in column(0). ViewState is enabled. I check the checkbox in first row of the grid on a page and then the program hits this event: Private Sub dgRegGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgRegGrid.PageIndexChanged I then do a loop to check the checkbox state.
5
1710
by: Patrick.O.Ige | last post by:
Hi Guys, I have a datagrid wit editing and updating. But after adding Paging IT WON'T PAGE!! It compiles well but when i click on the paging link it doesn't go to the next link.. When i remove AllowCutomPaging it gives error:- "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID MenuGrid when AllowPaging is set to true and the selected datasource does not implement ICollection"
3
2789
by: CVerma | last post by:
Hi, I have an embedded datagrid within a datalist. I am not able to perfrom paging in the datagrid. Any ideas? Here is my code: Here is my Simplegrid.cs file: using System; using System.Collections; using System.ComponentModel; using System.Data;
5
2797
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go to the database to get the next page. Is there a way to use the dataset to allow us to read back and forth in it instead of going back to the database to get it? Thanks,
0
1574
by: =?Utf-8?B?U2Vhblc=?= | last post by:
It appears that in the .NET Framework 2.0, if you create a datagrid, set AllowPaging="true", and set AutoGenerateColumns="true" the behaviour of the paging cell is incorrect, the ColumnSpan attribute is not rendered into the table cell data tag, and the table is invalid, with the paging appearing in the leftmost column, I have produced an example below. If you do this, you will get 3 columns. The paging will all appear in a column that...
0
1315
by: hanusoft | last post by:
This is an example of editing in DataGrid and Default Paging http://www.hanusoftware.com Html Design Code : - <asp:DataGrid id="DataGrid1" DataKeyField="id" runat="server" Height="224px" AutoGenerateColumns="False" PageSize="5" AllowPaging="True"> <Columns> <asp:BoundColumn Visible="False" DataField="id" HeaderText="Category Id"></asp:BoundColumn>
0
1662
by: webaccess | last post by:
Hi Friends ..!! I want to use datagrid/dataview control to data in tablular format,also I want to add paging and format the data of table column. Problem is data is coming from API Dom in as XML source. Now to display data i hv use dataset to fetch data.so i m displaying data in datagrid/dataview. Now here comes a problem: Using Datagrid :
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.