I am working on custom control. I am creating databound control. I have one property name RowDataSource that accept DataRowCollection as data source and I bind control on OnDataBinding event. I have another property name RowItem. My code looks like this.
public DataRowCollection RowDataSource
{
get
{
if (ViewState["rowDataSource"] == null)
{
ViewState["rowDataSource"] = null;
}
return (DataRowCollection)ViewState["rowDataSource"];
}
set
{
if (value == null)
{
throw new ArgumentException("unvalid data source.", this.ID);
}
ViewState["rowDataSource"] = value;
}
}
public RowCollections ExelRows
{
get
{
// rCollection is object of RowCollections class
if (rCollection == null)
{
rCollection = new RowCollections();
}
return rCollection;
}
}
OnDataBinding event code
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (RowDataSource != null)
{
foreach (DataRow dr in RowDataSource)
{
//RowItem is my class
RowItem item = new RowItem();
item.Text = dr[rTitle].ToString();
this.ExelRows.Add(item);
}
}
}
CreateChildControls method to render control
protected override void CreateChildControls()
{
if (ExelRows.Count > 0)
{
//here i am rendering table structure to add exelrows and create control.
}
}
Now, I am binding this control with DataRowCollection and It works file. I have one button in this control and I am raising bubble event when button is clicked. My problem is that when I click on button then CreateChildControls method is called first before OnDataBinding event. so I am getting ExelRows.Count = 0. so what I have to do to getting all rows on every bubble event of control. Thanks Imrankhan
please don't forget to vote on the post that helped you.