开发者

FindControl in DetailsView Not working?

I have a Gridview and when the edit button is clicked the details of that row is displayed using a detailsview.

While displaying, I need to find a control开发者_Python百科 in detailsView, and then bind it with a Datasource.

First of All I'm not sure about the event to be used but have used DetailsView1_DataBound. However, if I have to find the control using

var control=(ControlType)DetailsView1.Findcontrol("ID");

Always returns null. May be I am not using the right event, and it couldn't find the control at that point. Any ideas about the event to be used, and the right code please?

Thanks


In your databound event, you need to take care your DetailsView Mode

 if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
    {
      //Put here if you want to find control of your Edit Mode
      var control=(ControlType)DetailsView1.Findcontrol("EditTemplateControlID");
    }

 if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
    {
        //Put here if you want to find control of your Insert Mode
      var control=(ControlType)DetailsView1.Findcontrol("InsertTemplateControlID");
    }


I had the same problem and the answer of Muhammad Akhtar did not help me. The problem was solved after changing the default mode of the DetailsView from 'edit' to 'insert'.

I would also recommend the ItemCreated event instead of the DataBound event. I use it often for setting a default value in a field of the DetailsView.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜