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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:16:38+00:00 2026-05-11T13:16:38+00:00

I have created my first asp.net UserControl that I will use in several places

  • 0

I have created my first asp.net UserControl that I will use in several places throughout my app. It contains a FormView to display fields of the record in a DataTable.

It all seems fine, except, I can’t figure out how to set the DataSource on the FormView that is within the UserControl. I want to set the DataSource in a method in code-behind.

I see from intellisense that the UserControl does not have a DataSource property, but it does have a DataBind method. I can imagine that one might need to set different DataSources on multiple controls within a UserControl, so there must be some method for drilling into a UserControl, but I cannot figure it out.

Here is the aspx code:

<%@ Register src='Controls/JobDetail.ascx' tagname='JobDetail' tagprefix='uc1' %>   ...  <uc1:JobDetail ID='UserControlJobDetail' runat='server' />  ... 

Here is the method that attempts to set the DataSource:

public void BindJobRecord(string SelectedJobNo) {     UserControlJobDetail.DataSource = LMDataClass.GetJob(SelectedJobNo);     UserControlJobDetail.DataBind(); } 

And here is the UserControl:

<%@ Control Language='C#' AutoEventWireup='true' CodeBehind='JobDetail.ascx.cs' Inherits='DwgDatabase.JobDetail' %>  <asp:FormView ID='fvJobDetail' runat='server' DataKeyNames='job_num'>   <ItemTemplate>    <div style='float: left; border-width: 1px;' class='LabelStyle TextBoxStyle' >     <table>       <tr>        <td><asp:label runat='server' ID='lblJobNo' Text='Job No' /></td>        <td><asp:TextBox runat='server' ID='txtJobNo' Text='<%# Eval('job_num') %>' /></td>       </tr>       <tr>        <td><asp:label runat='server' ID='Label2' Text='Customer' /></td>        <td><asp:TextBox runat='server' ID='txtCustNo' Text='<%# Eval('cust_num') %>' /></td>       </tr>       <tr>         <td><asp:label runat='server' ID='Label3' Text='Quote No' /></td>         <td><asp:TextBox runat='server' ID='txtQuoteNo' Text='<%# DataBinder.Eval(Container.DataItem, 'quote_no', '{0:00000;;.}') %>' /></td>        </tr>        <tr>         <td><asp:label runat='server' ID='Label4' Text='Po No.' /></td>         <td><asp:TextBox runat='server' ID='TextBox4' Text='<%# Eval('p_o_num') %>' /></td>        </tr>     </table>             </div> </ItemTemplate>                </asp:FormView> 
  • 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. 2026-05-11T13:16:38+00:00Added an answer on May 11, 2026 at 1:16 pm

    Create a property DataSource on user control like below:

    public object DataSource {   get   {     return this.fvJobDetail.DataSource;   }   set   {     this.fvJobDetail.DataSource = value;   } } 

    Do the same for the DataBind() method.

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

Sidebar

Related Questions

I have created my first website using asp.net 3.5 . I have used App_Code
I have created a simple ASP.Net application, where first page accepts an input and
I use Entity Framework with ASP.NET MVC3 Code First. I have a project entity
I'm working on My First ASP.NET Application. I have created some text boxes and
I have an asp.net usercontrol that I'm using to put a bunch of HTML
I am developing a website by ASP.Net. I have created settings/first-run page which I
I created my first MVC application in ASP.NET today. I have a datetime column
I am building an asp.net MVC2 web app using StructureMap. I have created a
I have created a file argument.pl which takes several arguments first of which should
I have created an R script that it needs to load some libraries first.

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.