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

  • Home
  • SEARCH
  • 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 8590003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:11:35+00:00 2026-06-11T23:11:35+00:00

I want to create a data table when the aspx page is first loaded.

  • 0

I want to create a data table when the aspx page is first loaded. I have placed my code to create the data table with a blank row in a class file. Below is the code for creating the data table.

public class PaymentDetailsDataTable
{
    public PaymentDetailsDataTable()
    {
        DataTable pventries = new DataTable();

        DataColumn col1 = new DataColumn("col1");
        DataColumn col2 = new DataColumn("col2");
        DataColumn col3 = new DataColumn("col3");
        DataColumn col4 = new DataColumn("col4");
        DataColumn col5 = new DataColumn("col5");
        DataColumn col6 = new DataColumn("col6");
        DataColumn col7 = new DataColumn("col7");
        DataColumn col8 = new DataColumn("col8");
        DataColumn col9 = new DataColumn("col9");

        col1.DataType = System.Type.GetType("System.Int32");
        col2.DataType = System.Type.GetType("System.String");
        col3.DataType = System.Type.GetType("System.String");
        col4.DataType = System.Type.GetType("System.String");
        col5.DataType = System.Type.GetType("System.String");
        col6.DataType = System.Type.GetType("System.String");
        col7.DataType = System.Type.GetType("System.String");
        col8.DataType = System.Type.GetType("System.Double");
        col9.DataType = System.Type.GetType("System.String");

        pventries.Columns.Add(col1);
        pventries.Columns.Add(col2);
        pventries.Columns.Add(col3);
        pventries.Columns.Add(col4);
        pventries.Columns.Add(col5);
        pventries.Columns.Add(col6);
        pventries.Columns.Add(col7);
        pventries.Columns.Add(col8);
        pventries.Columns.Add(col9);

        pventries.Rows.Add();        

    }
} 

In my code behind file, I have instantiated my class and tried to use it as follows as follows:

    public partial class create_pv  : System.Web.UI.Page 
{
    String conn = WebConfigurationManager.ConnectionStrings["pvconn"].ToString();

    PaymentDetailsDataTable pmd = new PaymentDetailsDataTable();




    protected void Page_Load(object sender, EventArgs e)
    {


        /**/if(!IsPostBack)
            pmd.PaymentDetailsDataTable(); 
            allpventries.DataSource = pmd;
            allpventries.DataBind();
        }
}

Now when I try to access the method PaymentDetailsDataTable like this pmd.PaymentDetailsDataTable() I get the following error

'PaymentDetailsDataTable' does not contain a definition for 'PaymentDetailsDataTable' and no extension method 'PaymentDetailsDataTable' accepting a first argument of type 'PaymentDetailsDataTable' could be found (are you missing a using directive or an assembly reference?)  

If I change my method return type(PaymentDetailsDataTable) to void it works but I later want to bind the data table to a grid view(called allpventries) and it brings a compiler error.

How may I achieve binding a datagrid from a datatable whose code base is in a different class? Later I will be adding new rows to the datatable. Alternative options also acceptable to achieve this.

Very new in object oriented programming and C# ASP.NET.

  • 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-11T23:11:37+00:00Added an answer on June 11, 2026 at 11:11 pm

    The class PaymentDetailsDataTable should be a sub-class of DataTable or define a method in PaymentDetailsDataTable class which returns reference of DataTable object.

    public class PaymentDetailsDataTable : DataTable
    {
        public PaymentDetailsDataTable()
        {
            Columns.Add("Col1", typeof(int));
            Columns.Add("Col2");
    
            Rows.Add(1, "Foo");
            Rows.Add(2, "Bar");
        }
    }
    

    and code in page_load handler,

    protected void Page_Load(object sender, EventArgs e)
    {
      if(!IsPostBack)
       {
          allpventries.DataSource = new PaymentDetailsDataTable();
          allpventries.DataBind();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a html page that get data from a website table
I have data in 2 tables, and I want to create a report. Table
If I have a DataTable and want to create a new row I first
I want to create a data type as a TABLE but I can't use
I want to create a table with String keyvalues and integer data. Right now
I have created one jTable. I want to display the data into table from
I want to create a struct from data harvested by line from a file.
I have created a Area class using Linq-to-SQL. Now I want to create a
I want to access the data of table using WCF services. My code is
I have following table and data: create table Foo ( id int not null,

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.