Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:06:37+00:00 2026-06-17T09:06:37+00:00

I have 5 DropDownLists in GridView. I bind the grid with ObjectDataSource and also

  • 0

I have 5 DropDownLists in GridView. I bind the grid with ObjectDataSource and also bind the DropDownLists that belongs to GridView with 5 ObjectDataSources. Every thing is working fine. I capture first DropDownList SelectedIndexChanged event in C# and i want to bind 2nd DropDownList. Here is the code that i am using to bind second dropdownlist:

protected void Level1DropdownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList level1List = sender as DropDownList;
            if (level1List != null)
            {
                if (level1List.SelectedValue != "0")
                {
                    // Bind Level 2 List
                    GridViewRow currentRow = AnnouncementLevelsGrid.Rows[AnnouncementLevelsGrid.EditIndex];
                    if (currentRow != null)
                    {
                        DropDownList level2List = currentRow.FindControl("Level2DropdownList") as DropDownList;
                        if (level2List != null)
                        {
                            level2List.DataSource = AnnouncementHelper.GetLevel2(level1List.SelectedValue, EmployerHelper.EmployerID);
                            level2List.DataTextField = "Level2";
                            level2List.DataValueField = "Level2Value";
                            level2List.DataBind();
                        }
                    }
                }
            }
        }

Here is the asp.net code sample.

<asp:GridView ID="AnnouncementLevelsGrid" runat="server" Width="99%" DataSourceID="AnnouncementLevelsDataSource"
                                                    CssClass="Grid" AutoGenerateColumns="False" GridLines="None" DataKeyNames="AnnouncementLevelID,AnnouncementId"
                                                    ViewStateMode="Enabled" OnRowCommand="AnnouncementLevelsGrid_RowCommand" OnRowDataBound="AnnouncementLevelsGrid_RowDataBound"
                                                    OnRowUpdating="AnnouncementLevelsGrid_RowUpdating">
                                                    <HeaderStyle CssClass="GridHeader" />
                                                    <RowStyle CssClass="GridRow" />
                                                    <AlternatingRowStyle CssClass="GridAlternating" />
                                                    <Columns>
                                                        <asp:TemplateField HeaderText="Level 1">
                                                            <ItemTemplate>
                                                                <asp:Label ID="Level1Label" runat="server" Text='<%# Eval("Level1").ToString() == "0" ? "ALL" : Eval("Level1") %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <EditItemTemplate>
                                                                <asp:DropDownList ID="Level1DropdownList" runat="server" AppendDataBoundItems="True"
                                                                    DataTextField="Level1" DataValueField="Level1Value" SelectedValue='<%# Eval("Level1") %>'
                                                                    AutoPostBack="True" DataSourceID="Level1DataSource" OnSelectedIndexChanged="Level1DropdownList_SelectedIndexChanged">
                                                                    <asp:ListItem Text="All" Value="0"></asp:ListItem>
                                                                </asp:DropDownList>
                                                            </EditItemTemplate>
                                                            <HeaderStyle HorizontalAlign="Center" Width="18%" />
                                                            <ItemStyle HorizontalAlign="Center" Width="18%" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="Level 2">
                                                            <ItemTemplate>
                                                                <asp:Label ID="Level2Label" runat="server" Text='<%# Eval("Level2").ToString() == "0" ? "ALL" : Eval("Level2") %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <EditItemTemplate>
                                                                <asp:DropDownList ID="Level2DropdownList" runat="server" AppendDataBoundItems="True"
                                                                    DataTextField="Level2" DataValueField="Level2Value" SelectedValue='<%# Eval("Level2") %>'
                                                                    AutoPostBack="True" DataSourceID="Level2DataSource" OnSelectedIndexChanged="Level2DropdownList_SelectedIndexChanged">
                                                                    <asp:ListItem Text="All" Value="0"></asp:ListItem>
                                                                </asp:DropDownList>
                                                            </EditItemTemplate>
                                                            <HeaderStyle HorizontalAlign="Center" Width="18%" />
                                                            <ItemStyle HorizontalAlign="Center" Width="18%" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="Level 3">
                                                            <ItemTemplate>
                                                                <asp:Label ID="Level3Label" runat="server" Text='<%# Eval("Level3").ToString() == "0" ? "ALL" : Eval("Level3") %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <EditItemTemplate>
                                                                <asp:DropDownList ID="Level3DropdownList" runat="server" AppendDataBoundItems="True"
                                                                    DataTextField="Level3" DataValueField="Level3Value" SelectedValue='<%# Eval("Level3") %>'
                                                                    AutoPostBack="True" DataSourceID="Level3DataSource" OnSelectedIndexChanged="Level3DropdownList_SelectedIndexChanged">
                                                                    <asp:ListItem Text="All" Value="0"></asp:ListItem>
                                                                </asp:DropDownList>
                                                            </EditItemTemplate>
                                                            <HeaderStyle HorizontalAlign="Center" Width="18%" />
                                                            <ItemStyle HorizontalAlign="Center" Width="18%" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="Level 4">
                                                            <ItemTemplate>
                                                                <asp:Label ID="Level4Label" runat="server" Text='<%# Eval("Level4").ToString() == "0" ? "ALL" : Eval("Level4") %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <EditItemTemplate>
                                                                <asp:DropDownList ID="Level4DropdownList" runat="server" AppendDataBoundItems="True"
                                                                    DataTextField="Level4" DataValueField="Level4Value" SelectedValue='<%# Eval("Level4") %>'
                                                                    AutoPostBack="True" DataSourceID="Level4DataSource" OnSelectedIndexChanged="Level4DropdownList_SelectedIndexChanged">
                                                                    <asp:ListItem Text="All" Value="0"></asp:ListItem>
                                                                </asp:DropDownList>
                                                            </EditItemTemplate>
                                                            <HeaderStyle HorizontalAlign="Center" Width="18%" />
                                                            <ItemStyle HorizontalAlign="Center" Width="18%" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="Level 5">
                                                            <ItemTemplate>
                                                                <asp:Label ID="Level5Label" runat="server" Text='<%# Eval("Level5").ToString() == "0" ? "ALL" : Eval("Level5") %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <EditItemTemplate>
                                                                <asp:DropDownList ID="Level5DropdownList" runat="server" AppendDataBoundItems="True"
                                                                    DataTextField="Level5" DataValueField="Level5Value" SelectedValue='<%# Eval("Level5") %>'
                                                                    DataSourceID="Level5DataSource">
                                                                    <asp:ListItem Text="All" Value="0"></asp:ListItem>
                                                                </asp:DropDownList>
                                                            </EditItemTemplate>
                                                            <HeaderStyle HorizontalAlign="Center" Width="18%" />
                                                            <ItemStyle HorizontalAlign="Center" Width="18%" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField ShowHeader="False">
                                                            <ItemTemplate>
                                                                <asp:LinkButton ID="EditLink" runat="server" CausesValidation="False" CommandName="Edit"
                                                                    Text="Edit" ToolTip="Edit"><img src="images/edit.png" alt="Edit" style="border-width: 0px;" /></asp:LinkButton>
                                                            </ItemTemplate>
                                                            <EditItemTemplate>
                                                                <asp:LinkButton ID="UpdateLink" runat="server" CausesValidation="True" CommandName="Update"
                                                                    Text="Update" ToolTip="Update"><img src="images/Update-Grd.png" alt="Update" style="border-width: 0px;" /></asp:LinkButton>
                                                                &nbsp;<asp:LinkButton ID="CancelLink" runat="server" CausesValidation="False" CommandName="Cancel"
                                                                    Text="Cancel" ToolTip="Cancel"><img src="images/Cancel-Grd.png" alt="Cancel" style="border-width: 0px;" /></asp:LinkButton>
                                                            </EditItemTemplate>
                                                            <HeaderStyle HorizontalAlign="Center" Width="10%" />
                                                            <ItemStyle HorizontalAlign="Center" Width="10%" />
                                                        </asp:TemplateField>
                                                    </Columns>
                                                    <EmptyDataTemplate>
                                                        No Announcements Found.
                                                    </EmptyDataTemplate>
                                                </asp:GridView>
                                                <asp:ObjectDataSource ID="AnnouncementLevelsDataSource" runat="server" SelectMethod="GetAnnouncementLevels"
                                                    TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="AnnouncementLevelsDataSource_Selecting">
                                                    <SelectParameters>
                                                        <asp:Parameter Name="announcementID" DbType="Int64" />
                                                    </SelectParameters>
                                                </asp:ObjectDataSource>
                                                <asp:ObjectDataSource ID="Level1DataSource" runat="server" SelectMethod="GetLevel1"
                                                    TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level1DataSource_Selecting">
                                                    <SelectParameters>
                                                        <asp:Parameter Name="employerID" DbType="Int64" />
                                                    </SelectParameters>
                                                </asp:ObjectDataSource>
                                                <asp:ObjectDataSource ID="Level2DataSource" runat="server" SelectMethod="GetLevel2"
                                                    TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level2DataSource_Selecting">
                                                    <SelectParameters>
                                                        <asp:Parameter Name="employerID" DbType="Int64" />
                                                        <asp:Parameter Name="cc1" DbType="String" />
                                                    </SelectParameters>
                                                </asp:ObjectDataSource>
                                                <asp:ObjectDataSource ID="Level3DataSource" runat="server" SelectMethod="GetLevel3"
                                                    TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level3DataSource_Selecting">
                                                    <SelectParameters>
                                                        <asp:Parameter Name="employerID" DbType="Int64" />
                                                        <asp:Parameter Name="cc2" DbType="String" />
                                                    </SelectParameters>
                                                </asp:ObjectDataSource>
                                                <asp:ObjectDataSource ID="Level4DataSource" runat="server" SelectMethod="GetLevel4"
                                                    TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level4DataSource_Selecting">
                                                    <SelectParameters>
                                                        <asp:Parameter Name="employerID" DbType="Int64" />
                                                        <asp:Parameter Name="cc3" DbType="String" />
                                                    </SelectParameters>
                                                </asp:ObjectDataSource>
                                                <asp:ObjectDataSource ID="Level5DataSource" runat="server" SelectMethod="GetLevel5"
                                                    TypeName="LinkManagement.DataAccess.AnnouncementHelper" OnSelecting="Level5DataSource_Selecting">
                                                    <SelectParameters>
                                                        <asp:Parameter Name="employerID" DbType="Int64" />
                                                        <asp:Parameter Name="cc4" DbType="String" />
                                                    </SelectParameters>
                                                </asp:ObjectDataSource>

When i click edit button in grid view, all the dropdownlists render them in edit mode. They are also populating data correctly. Now when i change the first drop down list item in order to populate the second one, it throws the following exception :

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Can any body tell me how can i get rid of this problem. Do i need to handle another event of grid to bind the dropdown correctly? Also i want grid row still in edit mode after binding dropdown.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:06:38+00:00Added an answer on June 17, 2026 at 9:06 am

    Finally i am able to find the problem. I remove the UpdatePanel that surrounds GridView and debug the code. I found that my update function was getting null values except id value. Then i saw the gridview and find that i have selected each dropdownlist value in grid using Eval function which is used for one way databinding(Readonly). I replace it with Bind function and it start working fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdownlist in gridview and bind grid view from a function in
Background I have a GridView that builds a table using an ObjectDataSource . This
I have a gridview with sqldatasource, etc. For the grid, I also have a
I have a gridview that puts a drop down list in every cell of
I have a dropdownlist inside a gridview, that is loaded from a datasource when
I have a grid view that is data bound to a dataset. In a
I have a dropdownlist and the gridview and I want to bind the dropdownlist
I have a Gridview which binds to an ObjectDataSource (objStudentDetails). In edit/insert mode of
I have a SQL query that will result in one string. Rather than bind
I have a gridview in an ASP.NET site. There's a TemplateField right now that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.