473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Custom Usercontrol; Event not triggered

Hi all,
I have a Usercontrol containing a pre-formatted DataGrid and some code
which by default enables paging (with links 1..20). I now want to add
some extra paging information to the PagerTemplate using the code below.

It does show me all the labels and links, but the event I attach to the
previous and next links isn't triggered on click. I must be doing
something wrong, perhaps you can help me out?

TIA

--- the code (hope it's readable) ---
private void grid_ItemCreated(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Pager)
{
// Extract the Pager
TableCell pager = (TableCell)e.Item.Controls[0];

//Add Cell to Row to Hold Row Count Label
TableCell newcell = new TableCell();
newcell.ColumnSpan = this.grid.Columns.Count / 2;
newcell.HorizontalAlign = HorizontalAlign.Left;
newcell.ID = "pagerInfo";

//Add Table Cell to Pager
e.Item.Controls.AddAt(0, newcell);

//Subtract from Colspan of Original Pager to Account for New Row
pager.ColumnSpan = pager.ColumnSpan - 1;
}
}

private void grid_PreRender(object sender, EventArgs e)
{
try
{
// add pagerinfo to top and bottom pagertemplate

this.GridPagingInfo(((TableCell)grid.Controls[0].Controls[0].FindControl("pagerInfo")));

this.GridPagingInfo(((TableCell)grid.Controls[0].Controls[grid.Controls[0].Controls.Count
- 1].FindControl("pagerInfo")));

}
catch
{}
}

private void GridPagingInfo(TableCell p) {
if (this.RecordCount 0)
{

Label pageInfo = new Label();
/* paging info */
pageInfo.Text = this.RecordCount.ToString() + " records ";
pageInfo.Text += "| " +
this.grid.Items.Count.ToString() + " shown | " +
"Page " + (this.grid.CurrentPageIndex + 1).ToString() + " of " +
Math.Ceiling(Convert.ToDouble(this.RecordCount)/this.grid.PageSize);

p.Controls.Add(pageInfo);
p.Controls.Add(new Seperator());

// previous-button
if (this.grid.CurrentPageIndex 0)
{
LinkButton gridPreviousLink = new LinkButton();
gridPreviousLink.Text = "Previous";
p.Controls.Add(gridPreviousLink);
gridPreviousLink.Click += new EventHandler(gridPreviousLink_Click);
}
else
{
Label gridPreviousLabel = new Label();
gridPreviousLabel.Text = "Previous";
gridPreviousLabel.ForeColor =
System.Drawing.ColorTranslator.FromHtml("#999999") ;
p.Controls.Add(gridPreviousLabel);

}
p.Controls.Add(new Seperator());

// next-button
if ((this.grid.CurrentPageIndex ) < (this.RecordCount / this.PageSize))
{

LinkButton gridNextLink = new LinkButton();
gridNextLink.Text = "Next";
p.Controls.Add(gridNextLink);
gridNextLink.Click += new EventHandler(gridNextLink_Click);
}
else
{
Label gridNextLabel = new Label();
gridNextLabel.Text = "Next";
gridNextLabel.ForeColor =
System.Drawing.ColorTranslator.FromHtml("#999999") ;
p.Controls.Add(gridNextLabel);
}

}

}
Jul 19 '06 #1
0 984

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

Similar topics

1
by: Dennis | last post by:
I'm using VS 2003 my project uses COM interop and the Tao Framework. I have a custom control derived from UserControl. It implements many functions similar to the Tao's SimpleOpenGLControl, for...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
3
by: Chu | last post by:
Hello All- I've got a Custom Web Control that with a public class that that sets a private variable inside the class. I plop the custom control onto my page and off I go. From my main page, I...
0
by: Sjaakie | last post by:
Hi all, I have a Usercontrol containing a pre-formatted DataGrid and some code which by default enables paging. I now want to add some extra paging information to the PagerTemplate using the code...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
6
by: tshad | last post by:
I was looking at a page that showed how to set up a custom event and it seems to work ok. But I am not sure how I would use it. How would I subscribe to it. There is actual action (such as...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.