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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:32:41+00:00 2026-06-18T19:32:41+00:00

I have a super simple gridview setup in a user control like this: <asp:GridView

  • 0

I have a super simple gridview setup in a user control like this:

    <asp:GridView ID="gvTestUC" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField DataField="FirstName" HeaderText="First Name" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" />
            <asp:BoundField DataField="LastName" HeaderText="Last Name" />
            <asp:BoundField DataField="EmailAddress" HeaderText="Email Address" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" />
        </Columns>
</asp:GridView>

I am registering the user control like this:

<%@ Register src="Controls/test1.ascx" tagname="test1" tagprefix="test1uc" %>
<test1uc:test1 ID="test1a" runat="server" />

My problem is, is that I can’t figure out how to databind it in the .aspx page that is using the user control.

I tried doing:

test1a.gvTestUC

But it can’t find the gridview.

The reason I am trying to databind the gridview from the .aspx page, is because all the pages that need this user control, will need to bind different data to the gridview that is inside it.

Any help would be appreciated.

Thanks!

  • 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-18T19:32:42+00:00Added an answer on June 18, 2026 at 7:32 pm

    You just have to provide a public method which you can call from your page.

    in your UserControl:

    Public Sub BindData(gridSource As ComponentModel.IListSource)
        BindGridView(dataSource)
    End Sub
    
    Private Sub BindGridView(gridSource As ComponentModel.IListSource)
        gvTestUC.DataSource = gridSource 
        gvTestUC.DataBind()
    End Sub
    

    in your Page when you want to databind it:

    test1a.BindData(GetGridDataSource())
    

    Side-note: never let a UserControl databind itself from Page_Load. This can cause nasty side-effects, removes control from the page which is meant to be the controller and will prevent lazy-loading your control when you want (f.e. on TabIndexChanging with a TabContainer control).

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

Sidebar

Related Questions

I have this super simple jQuery script that I'm having trouble getting to work.
This page I have is super simple, this should be a breeze but I'm
This really should be so very simple... I have an asp.net master page which
I'd like to have a super simple / fast encrypt/decrypt function for non-critical pieces
This should be super simple but I keep getting errors. I have a JSON
I have a super-simple query in a star schema. One fact, two dimensions. I
Here is the super simple code i have: HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.OptionWriteEmptyNodes
Let's say I have a super type (Shape) and two children (like Square, Circle).
I have a super-simple class representing a decimal # with fixed precision, and when
I have made a super simple test case of a problem I'm having with

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.