• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

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

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.
<asp:GridView 
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">
                   <HeaderTemplate>
                        <table style="width: 500px" cellspacing="0" cellpadding="0">
                            <tr>
                                <td style="width: 200px;">
                                    Description</td>
                                <td style="width: 60px;">
                                    Account</td>
                                <td style="width: 200px;">
                                    Category</td>
                            </tr>
                        </table>
                    </HeaderTemplate>
                
                    <ItemTemplate>
                        <table style="width: 500px" cellspacing="0" cellpadding="0">
                            <tr>
                                <td style="width: 200px;">
                                    <%# DataBinder.Eval(Container.DataItem,"DESCRIPTION")%>
                                </td>
                                <td style="width: 60px;">
                                    <%# DataBinder.Eval(Container.DataItem, "ACCOUNT")%>
                                </td>
                                <td style="width: 200px;">
                                    <%# DataBinder.Eval(Container.DataItem,"CATEGORY")%>
 
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:DropDownList>
                </EditItemTemplate>
                </asp:GridTemplateColumn>
 
</asp:GridView>
 
 <asp:ObjectDataSource ID="odsInvLines" TypeName="ARA.Facilities.IDC.IDC" runat="server"
         OldValuesParameterFormatString="original{0}" SelectMethod="GetInvoiceLinesByInvoiceID" InsertMethod="UpdateInvoiceLines" UpdateMethod="UpdateInvoiceLines">
        <UpdateParameters>
        <asp:QueryStringParameter Name="InvoiceID" QueryStringField="invoice_id" Type="Int64" />
        <asp:Parameter COntrolID="ddlActivityCodes" Property="SelectedValue" Type="String" />
        </UpdateParameters>
   </asp:ObjectDataSource>

Open in new window

0
tech_question
Asked:
tech_question
2 Solutions
 
Kalpana_NatarajanCommented:
Try using the clientId of the control when accessing the control from the codebehind. This will give oyu access to the dorpdownlist.
0
 
GiftsonDJohnCommented:
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.
0
 
tech_questionAuthor Commented:
I used the bind property and it works.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now