I have made a Custom Repeater. In the DataBind event, I am using a PagedDataSource (which persists) and I am determining how to grab my data from there. This works fine when I bind a datasource directly to the control. However, when I use the DataSourceID property, it binds the data, but my PagedRepeater doesn't work anymore. This leads me to believe that something behind the scenes, related to the DataSourceID is interfering with my databinding.
In the OnInit event for my control, I have the following code:
if (DataSourceID != "")
{
string dis = DataSourceID;
DataSourceID = "";
DataSource = this.NamingContainer.FindControl(dis);
DataBind();
}
if (AllowPaging)
this.RequiresDataBinding = true;
base.OnInit(e);
This works well, as long as I explicitly call the DataBind event for the control, however, this is not how most databound controls function when specifying the DataSourceID. My question is how do I ensure it gets databound when there is a datasourceID? When should I be checking the DataSourceID and converting it to the DataSource, or should I be doing that at all?
In the ItemDataBound event for my control, I have the following code:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label l = e.Item.FindControl("lblText") as Label;
l.Text = ((DataRowView)e.Item.DataItem)["title"].ToString() + " " + DateTime.Now.ToLongTimeString();
}
The expected behavior here is that it will display the time next to the "Title" from the DataSource row. It works when explicitly calling the DataBind method for the control, and the time updates between postbacks. When I use DataSourceID, however, it never updates the time (it is displayed, but it is always the value of when the page was loaded) and the value inside the repeater item remains the same. The most confusing aspect of this, to me, is that when I debug, and set a breakpoint in this method, it seems to specify the correct information, however, it doesn't display it. It always displays the old information.
If anyone can give me some advice on this issue, I'd really appreciate it.