PC Review


Reply
Thread Tools Rate Thread

Custom Usercontrol; Event not triggered

 
 
Sjaakie
Guest
Posts: n/a
 
      20th Jul 2006
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);
}

}

}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2nd event triggered within an event handler =?Utf-8?B?TWF4IDFlNg==?= Microsoft VB .NET 2 16th Apr 2007 11:22 PM
What triggered this event? Daniel Manes Microsoft Dot NET 1 18th Dec 2006 12:16 PM
Custom Usercontrol; Event not triggered Sjaakie Microsoft ASP .NET 0 19th Jul 2006 09:55 AM
ASP.NET 2.0 Raising a custom event from a usercontrol to parent page: How? Jimi Microsoft ASP .NET 1 26th Mar 2006 03:12 AM
Custom Event Handling within UserControl =?Utf-8?B?Tmljb2xlIC0gQVNQL0MjIEJlZ2lubmVy?= Microsoft Dot NET 2 15th Oct 2004 09:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 AM.