how to get the value of the of a drop down list in a gridview and bind it to the datasource ?

Posted on 2009-04-24
Last Modified: 2012-06-21
in the below  code, I am getting error control ddlActivityCodes cannot be found. I cut short the gridview as it is too long. I am pasting the relevant code. What should be the control ID during run time inside the gridview ? How would I get the selected value of the dropdown list in an edit mode - and send this to the objectdatasource.

ID="gridInvLines" AllowPaging="False" runat="server" AutoGenerateColumns="False" DataSourceID="odsInvLines">


<asp:DropDownList ID="ddlActivityCodes"  runat="server" Height="200px"

                AllowCustomText="False" ShowToggleImage="True" ShowMoreResultsBox="false"    

                    EnableLoadOnDemand="True" DropDownWidth="500px" DataTextField="DESCRIPTION"  DataSource='<%# LoadActivityCodes() %>' 

                      MarkFirstMatch="True" SelectedValue='<%# DataBinder.Eval(Container.DataItem, "Rev_Activity_Code_ID") %>'  DataValueField="Rev_Activity_Code_ID"  Text='<%# DataBinder.Eval(Container.DataItem, "ACTIVITY_CODE_DESC") %>'  AppendDataBoundItems="true" OnClientItemsRequesting="" AutoPostBack="false"  Skin="Office2007">


                        <table style="width: 500px" cellspacing="0" cellpadding="0">


                                <td style="width: 200px;">


                                <td style="width: 60px;">


                                <td style="width: 200px;">







                        <table style="width: 500px" cellspacing="0" cellpadding="0">


                                <td style="width: 200px;">

                                    <%# DataBinder.Eval(Container.DataItem,"DESCRIPTION")%>


                                <td style="width: 60px;">

                                    <%# DataBinder.Eval(Container.DataItem, "ACCOUNT")%>


                                <td style="width: 200px;">

                                    <%# DataBinder.Eval(Container.DataItem,"CATEGORY")%>










 <asp:ObjectDataSource ID="odsInvLines" TypeName="ARA.Facilities.IDC.IDC" runat="server"

         OldValuesParameterFormatString="original{0}" SelectMethod="GetInvoiceLinesByInvoiceID" InsertMethod="UpdateInvoiceLines" UpdateMethod="UpdateInvoiceLines">


        <asp:QueryStringParameter Name="InvoiceID" QueryStringField="invoice_id" Type="Int64" />

        <asp:Parameter COntrolID="ddlActivityCodes" Property="SelectedValue" Type="String" />



Open in new window

Question by:tech_question
    LVL 2

    Assisted Solution

    Try using the clientId of the control when accessing the control from the codebehind. This will give oyu access to the dorpdownlist.
    LVL 14

    Expert Comment

    Is the above code executes normally?

    The Dropdownlist is not under any templates. It is outside  and the templates are inside the dropdownlist as the child element. DropDownlist doesn't contain any HeaderTemplate or ItemTempate. It will definitely throw error.

    Accepted Solution

    I used the bind property and it works.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now