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 6901913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:43:59+00:00 2026-05-27T07:43:59+00:00

I have user control with a gridview, but for some reason I can’t use

  • 0

I have user control with a gridview, but for some reason I can’t use the asp controls from within the backend code.
In the other user controls I can use them normally but at this particular user control it gives me error when I am trying to use a control which is used in the gridview.
Here is the code for my gridview, please let me know if you notice something unusual:

<asp:GridView ID="gvGDG" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="ID" DataSourceID="SqlDataSource1" Width="100%" CssClass="mGrid" GridLines="None" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
    AllowPaging="True" >
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
            ItemStyle-HorizontalAlign="Center" CausesValidation="False">
        </asp:CommandField>
        <asp:BoundField DataField="ID" HeaderText="ID" 
            SortExpression="ID" InsertVisible="False" ReadOnly="True" 
            ItemStyle-HorizontalAlign="Center" >
        </asp:BoundField>      
        <asp:TemplateField HeaderText="Country" SortExpression="Country">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Country") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
            <asp:UpdatePanel ID="countrypanel" runat="server">            
            <ContentTemplate>
            <asp:DropDownList ID="ddlCountry" runat="server" DataTextField="name" DataValueField="ID"  onselectedindexchanged="ddlcountry_SelectedIndexChanged" AppendDataBoundItems="true" AutoPostBack="true" />
            </ContentTemplate>
            <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlCountry" />
            </Triggers>
            </asp:UpdatePanel>
            </EditItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="State Province" SortExpression="State_Province">
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("State_Province") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                             <asp:DropDownList ID="ddlState" runat="server" DataSourceID="SqlDataSource3" SelectedValue='<%# Bind("State_Province") %>'
                                 DataTextField="StateName" DataValueField="StateName">
                </asp:DropDownList>
                             <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                                 ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                                 SelectCommand="SELECT [StateName] FROM [States]"></asp:SqlDataSource>
            </EditItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
                <asp:TemplateField HeaderText="GDG Type" SortExpression="State_Province">
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("GDG_Type") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                             <asp:DropDownList ID="ddlGdg" runat="server" DataSourceID="SqlDataSource4" SelectedValue='<%# Bind("GDG_Type") %>'
                                 DataTextField="GDG" DataValueField="GDG">
                </asp:DropDownList>
                             <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
                                 ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                                 SelectCommand="SELECT [GDG] FROM [GDG]"></asp:SqlDataSource>
            </EditItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>

          <asp:TemplateField HeaderText="Energy Type UOM" SortExpression="Energy_Type_UOM">
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Bind("Energy_Type_UOM") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                             <asp:DropDownList ID="ddlUomEnergy" runat="server" DataSourceID="SqlDataSource5" SelectedValue='<%# Bind("Energy_Type_UOM") %>'
                                 DataTextField="UOM" DataValueField="UOM">
                </asp:DropDownList>
                             <asp:SqlDataSource ID="SqlDataSource5" runat="server" 
                                 ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                                 SelectCommand="SELECT UOM FROM UOM WHERE (Type = 'E')"></asp:SqlDataSource>
            </EditItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>


                      <asp:TemplateField HeaderText="GDG UOM" SortExpression="GDG_UOM">
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# Bind("GDG_UOM") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                             <asp:DropDownList ID="ddlUom" runat="server" DataSourceID="SqlDataSource6" SelectedValue='<%# Bind("GDG_UOM") %>'
                                 DataTextField="UOM" DataValueField="UOM">
                </asp:DropDownList>
                             <asp:SqlDataSource ID="SqlDataSource6" runat="server" 
                                 ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
                                 SelectCommand="SELECT UOM FROM UOM WHERE (Type = 'O')"></asp:SqlDataSource>
            </EditItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>     
        <asp:BoundField DataField="GDG_Coeficient_Value" 
            HeaderText="GDG Coeficient Value" SortExpression="GDG Coeficient Value" 
            ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:BoundField>
    </Columns>

<PagerStyle CssClass="pgr"></PagerStyle>
</asp:GridView>

Thanks in advance, Laziale

  • 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-05-27T07:43:59+00:00Added an answer on May 27, 2026 at 7:43 am

    If I m right then. You have a User Control. Say wucMyControl.ascx, where you have a gridview control gvGDG. And u are unable to access it from wucMyControl.ascx.cs. If its the problem then use the solution below:

    In your user controls designer file check the access level of the Gridview control. Might be it will get changed to private, accidently , instead of protected. If its private , make it protected or public and check whether you are able to access it now or not.

    Update
    FYI, you can’t access directly the child controls. For this you need to access in the controls DataBound event.

    Here in your case :

    protected void GridView_RowDataBound(sender, e)
    {
        if(e.Row.RowType == DataControlRowtype.DataRow)
         {
              var ddl = (DropdownList)e.Row.FindControl("ddlCountry");
              // do whatever you want with ddl. Similarly you can find all html and server control inside a gridview.
         }
    }
    

    This will help you…

    Adding event to gridview child controls

    In your GridView1_RowDataBound method, add the handler when you create the drop down by calling ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);

    Then, declare the void ddl_SelectedIndexChanged(object sender, EventArgs e) method to handle your logic. The sender argument will be a reference to the drop down’s that was selected. Also set AutoPostback property of the drodownlist to true.

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

Sidebar

Related Questions

I have a GridView inside of a User Control populated from a List of
I have a ASP.NET GridView that uses template columns and user controls to allow
I have a user control that contains a GridView. The GridView has both a
In my child user control I have a gridview with an OnRowCommand eventhandler that
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have a user control that is pretty basic. It contains several TextBox controls,
I have a custom ASP.NET user control that is added to a panel on
I have a button on my ASP.NET page, which fetches some data from my
I have a gridview control with delete asp:ImageButton for each row of the grid.
I have a PlannerShiftView user control in the root folder of my ASP.NET web

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.