开发者

not able to find usercontrol in edittemplate of datalist

i have a webusercontrol in the edittemplate of the datalist. in the code behind, in the itemCommand, when i try to find it using findcontrol, i get null object.

what is it that i am doing wrong?

WebUserControl cntrl = (WebUserControl)e.Item.FindControl("myControl");

or i also tried the below, in the EditCommand event, 开发者_StackOverflow社区because i have kept the usercontrol inside the EditTemplate of the DataList:

WebUserControl cntrl = (WebUserControl)DataList1.FindControl("myControl");


I think you're probably doing something like this :

    protected void gridView_rowDataBound(Object sender, GridViewRowEventArgs e)
    {
        WebUserControl cntrl = (WebUserControl)e.Item.FindControl("myControl");
    }

Keep in mind that you'd be looking at every single row - including the header and footer rows.

I think you need this :

    protected void gridView_rowDataBound(Object sender, GridViewRowEventArgs e)
    {
       if (e.Row.RowType == DataControlRowType.DataRow){
            WebUserControl cntrl = (WebUserControl)e.Item.FindControl("myControl");
       }
    }


Actually never mind, i moved the control to the headertemplate and looking at its controls collection, i am able to find the control using FindControl. Not sure why its not finding if i place it in the edititemtemplate. but thanks guys appreciate your help.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜