473,387 Members | 1,515 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,387 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. 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 20 '06 #1
0 1015

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...
2
by: Frank | last post by:
Hi! I have a really 'simple' problem. I have an .aspx page with 2 textboxes (login & password) and a Submit button. This works very well, i fill in my login and password and simply press the...
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 (with links 1..20). I now want to add some extra paging information to the...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.