开发者

How to use a UserControl inside the EditTemplate of a ListVIew?

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 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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜