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
(withCommandName="Edit"
) in each row - Event handlers for
OnItemDataBound
andOnItemEditing
- A UserControl in
EditTemplate
.
Now the problem is, I don't know how to use Bind
expression in the UserCont开发者_运维知识库rol. 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.)
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
TheClass theControl = (TheClass)e.Item.FindControl("theControl)";
theControl.someProperty = "bla bla bla";
}
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.
精彩评论