Cannot acess DropDownList in EditItemTemplate within a DetailsView

Last post 01-18-2007 4:16 AM by bhav27. 3 replies.

Sort Posts:

  • Cannot acess DropDownList in EditItemTemplate within a DetailsView

    11-17-2006, 11:56 AM
    • Loading...
    • jbarrcfl
    • Joined on 11-17-2006, 4:40 PM
    • Posts 2
    I am trying to access a dropdown list control that is in a detailsview:

    <asp:TemplateField HeaderText="Person" SortExpression="PersonId">

       <EditItemTemplate>

          <asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative" OnDataBound="DropDownList1_DataBound">

          </asp:DropDownList>

       </EditItemTemplate>

    </asp:TemplateField>

    I am trying to access it to get and set it selectedindex on different events from other controls on the page.  I have tried to use

    DetailsView1.FindControl("DropDownList1")   <-- Also have just tried just   FindControl .... no DetailsView1

    I always get null. And DropDownList1 fails to show-up in intellisense.

    I have looked through other post and other sources but have not seen a direct answer to this problem?

    Thank you in advance

  • Re: Cannot acess DropDownList in EditItemTemplate within a DetailsView

    11-17-2006, 12:06 PM
    • Loading...
    • Mike Bell
    • Joined on 07-08-2005, 7:06 PM
    • Tulsa, Oklahoma
    • Posts 125
    You won't be able to access it unless the gridview CurrentMode is EditMode, but once it's there... you can do:
    DetailsView1.Rows[#].Cells[#].FindControl("DropDownList1")
    Mike Bell
    My Code Blog
  • Re: Cannot acess DropDownList in EditItemTemplate within a DetailsView

    11-17-2006, 1:49 PM
    • Loading...
    • jbarrcfl
    • Joined on 11-17-2006, 4:40 PM
    • Posts 2

    (DropDownList)DetailsView1.FindControl("DropDownList1");  ---  Has worked, although my case is simplified by keeping setting the DetailsView -> DefaultMode -> Edit
    I think wraps this up. I am a little disappointed that it can't be accessed by just using   DropDownList1. ...

    Thanks
  • Re: Cannot acess DropDownList in EditItemTemplate within a DetailsView

    01-18-2007, 4:16 AM
    • Loading...
    • bhav27
    • Joined on 06-07-2006, 12:10 PM
    • Posts 61

    see this forum

    http://forums.asp.net/1537657/ShowThread.aspx#1537657 

Page 1 of 1 (4 items)
Microsoft Communities
Page view counter