All,
It may be because of have an OnItemCreated in the grid, and a similar event on my web page - here's the one on the grid
protected override void OnItemCreated(System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//* Create the message and seperator for the pager control.
if ( e.Item.ItemType == ListItemType.Pager )
{
//* Variables for use in calculating the available items.
int lowerItemNumber = 0;
int upperItemNumber = 0;
//* Build the pager message part.
//* If this grid uses built-in paging mechanisms, the information needed to create the label will be available
//* internally. Otherwise, we must examine the externally available properties, (LowerItemNumber, UpperItemNumber,
//* and TotalItemCount)
Label lblPagerMessage = new Label();
lblPagerMessage.CssClass = "Text9pt";
//* Make sure the user set the appropriate properties.
if (this.Items.Count > 0 )
{
lowerItemNumber = (1 + (this.PageSize * this.CurrentPageIndex));
upperItemNumber = ((this.PageSize * this.CurrentPageIndex) + this.Items.Count);
int TP = this.VirtualItemCount/this.PageSize;
if ( (TP * this.PageSize) != this.VirtualItemCount )
{
TP += 1;
}
lblPagerMessage.Text = String.Format("Displaying {5} records Per Page - Display Records {0} to {1} of {2} | Page {3} of {4} | ",
lowerItemNumber,
((this.PageSize * this.CurrentPageIndex) + this.Items.Count),
this.VirtualItemCount,
this.CurrentPageIndex + 1,
TP,
this.PageSize);
}
else
{
lblPagerMessage.Text = this.emptyMessage + " | ";
}
//* Get the controls within the pager into an array then clear the pager out.
ArrayList aControls = new ArrayList();
foreach ( Control c in e.Item.Cells[0].Controls )
{
aControls.Add(c);
}
e.Item.Cells[0].Controls.Clear();
//* Re-insert controls including message label and item seperators.
e.Item.Cells[0].Controls.Add(lblPagerMessage);
for ( int i=0; i<aControls.Count; i++)
{
Control c = (Control)aControls;
//* If we are between the "Previous" and the "Last" buttons, or
//* if this control uses numbers as well, insert pipes between each link.
if (i == aControls.Count - 2)
{
Label oLine = new Label();
oLine.Text = " | ";
oLine.CssClass = "Text9pt";
e.Item.Cells[0].Controls.Add(oLine);
}
//* Make the Next and Previous buttons
if (c is LinkButton || c is Label)
{
((WebControl)c).CssClass = "Text9ptBlue";
}
e.Item.Cells[0].Controls.Add(c);
}
}
base.OnItemCreated(e);
}
Here's the one on the web page:
public void grdNetwork_People_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem )
{
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#C0C0C0';this.style.cursor='hand'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='" + (e.Item.ItemType == ListItemType.Item ? "#FFFFE0" : "#FFFFFF") + "';");
if ( e.Item.DataItem != null )
{
//e.Item.Cells[0].ToString();
string PK = ((DataRowView)(e.Item.DataItem)).Row.ItemArray[0].ToString();
e.Item.Attributes.Add("onclick", "ViewService('" + PK + "')");
}
}
}
How can I interleave the two - and not have the ListItemType.Pager item be gnerated more than once? Can I - or is this just how the events bubble up?
Doug