views:

22

answers:

2

Here is the situation:

  • I have a ListView showing just a list of concatenated strings obtained from different field of the objects of the datasource.
  • A LinkButton (with CommandName="Edit") in each row
  • Event handlers for OnItemDataBound and OnItemEditing
  • A UserControl in EditTemplate.

Now the problem is, I don't know how to use Bind expression in the UserControl. I mean, how to populate this usercontrol when the linkbutton is clicked? (I tried capturing the control in the OnItemEditing handler. But FindControl returned null, as that handler is called before going to edit mode.)

A: 
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    TheClass theControl = (TheClass)e.Item.FindControl("theControl)";
    theControl.someProperty = "bla bla bla";
}
y34h
Problem is, 'e.Item.FindControl("theControl)"' does not return the usercontrol (in the EditTemplate)
mshsayem
A: 

Finally got an answer from asp.net forum. The solution is:

  • Modify the UserControl so that, it supports DataBinding. To do that, implement the DefaultBindingPropertyAttribute. Details here.
mshsayem