Re: ItemDataBound not Firing on Repeater
"Efran Cobisi, cobisi.com" <[email protected]> Sun, 9 Sep 2007 16:04:51 +0200
| Newsgroups | gmane.comp.windows.devel.dotnet.web |
|---|---|
| Organization | cobisi.com |
| Message-ID | <[email protected]> |
Hi Brady,
Your issue is basically due to the fact that you are wiring up the
ItemDataBound event of the inner repeater AFTER it has been data bound.
The Load event for controls hosted inside a given Page instance are
fired AFTER the Load event has been fired for the aforementioned Page
instance. So, since you are data binding the control inside the Load
event for the page, it will be data bound before the Load event for the
control is fired.
To solve this one, just move the event wire up code in an event handler
wich would take place before the Load event. For example, the Init event
would be ok; here's some code:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// Events wire up
rptPageButtons.ItemDataBound += new
RepeaterItemEventHandler(rptPageButtons_ItemDataBound);
}
Hope this helps.
--
Efran Cobisi
http://www.cobisi.com
Brady Kelly wrote:
> This is my code in the page hosting my control. The pgnTest.DataSource and
> pgnTest.DataBind calls refer to the methods described below, from my
> previous post:
>
> protected void Page_Load(object sender, EventArgs e)
> {
> // pgnTest is a Paginator control on this test page.
> DataTable emps = SqlDataProvider.GetEmployees();
> pgnTest.DataSource = emps;
> pgnTest.DataBind();
> }
>
>
> public partial class Paginator : System.Web.UI.UserControl
> {
> PagingManager pagingManager = new PagingManager();
> protected void Page_Load(object sender, EventArgs e)
> {
> // This doesn't hook up the event, while using the attribute
> on the Repeater does.
> rptPageButtons.ItemDataBound += new
> RepeaterItemEventHandler(rptPageButtons_ItemDataBound);
> }
>
> protected void rptPageButtons_ItemDataBound(object sender,
> RepeaterItemEventArgs e)
> {
> Button btnPage = e.Item.FindControl("pageButton") as Button;
> DataRowView drv = e.Item.DataItem as DataRowView;
> if (drv != null)
> {
> btnPage.Attributes.Add("PageKey",
> drv["PageKey"].ToString());
> btnPage.Text = drv["PageDesc"].ToString();
> }
> }
>
> public DataTable DataSource
> {
> set
> {
> pagingManager.MaxPageSize = 15;
> pagingManager.PaginateDataTable(value);
> rptPageButtons.DataSource = pagingManager.PagesDataTable;
> }
> }
>
> public new void DataBind()
> {
> rptPageButtons.DataBind();
> }
> }
>
> ===================================
> This list is hosted by DevelopMentor® http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>
>
>
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com