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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:11:28+00:00 2026-05-10T20:11:28+00:00

I have a gridview like below: <asp:GridView DataKeyNames=TransactionID AllowSorting=True AllowPaging=TrueID=grvBrokerage runat=server AutoGenerateColumns=False CssClass=datatable Width=100%

  • 0

I have a gridview like below:

 <asp:GridView DataKeyNames='TransactionID'                 AllowSorting='True' AllowPaging='True'ID='grvBrokerage'                 runat='server' AutoGenerateColumns='False'                 CssClass='datatable' Width='100%'               <Columns>                   <asp:BoundField DataField='BrkgAccountNameOutput'                                                 HeaderText='Account Name'/>                   <asp:BoundField DataField='TransactionAmount'                                    HeaderText='Transaction Amount'                                    SortExpression='TransactionAmount' />                   <asp:BoundField DataField='TransType'                                    HeaderText='Transaction Type'                                             SortExpression='TransType'/>                   <asp:BoundField DataField='AccountBalance'                                    HeaderText='Account Balance'/>                   <asp:BoundField DataField='CreateDt'                                    HeaderText='Transaction Date'  />                </Columns>  </asp:GridView> 

I have a page with a gridview and a objectdatasource control. AllowPaging and AllowSorting is enabled. Here is the method I use that gets the data and binds the objectdatasource to the grid:

        protected void BindBrokerageDetails()         {             HomePage master = (HomePage)Page.Master;              BrokerageAccount brokerageAccount = new BrokerageAccount();             brokerageAccount.UserID = new Guid(Membership.GetUser().ProviderUserKey.ToString());               ddlBrokerageDetails.DataSource = brokerageAccount.GetAll();             ddlBrokerageDetails.DataTextField = 'Account Name';             ddlBrokerageDetails.DataValueField = 'Account Name';             ddlBrokerageDetails.DataBind();            if (ddlBrokerageDetails.Items.Count > 0)            {                BrokerageTransactions brokerageaccountdetails = new                                                      BrokerageTransactions();                DataSet ds = BrokerageAccount.GetBrkID2(                                     new Guid(Membership                                               .GetUser()                                               .ProviderUserKey                                               .ToString()),                                     ddlBrokerageDetails                                               .SelectedItem                                               .Text                                               .ToString());                foreach (DataRow dr in ds.Tables[0].Rows)                {                    brokerageaccountdetails.BrokerageId = new Guid(dr['BrkrgId'].ToString());                }                 ddlBrokerageDetails.SelectedItem.Value = brokerageaccountdetails.BrokerageId.ToString();                grvBrokerage.DataSource = ObjectDataSource1;                grvBrokerage.DataBind();            }                  } 

I have a sorting event, but when I check the grvBrokerage.DataSource, it is null. I am curious as to why? Here is the code for that?

  protected void grvBrokerage_Sorting(object sender, GridViewSortEventArgs e)        {                          DataTable dt = grvBrokerage.DataSource as DataTable;              if (dt != null)             {                                   DataView dv = new DataView(dt);               dv.Sort = e.SortExpression + ' ' + e.SortDirection;                   grvBrokerage.DataSource = dv;               grvBrokerage.DataBind();            }        } 

Here is the ObjectDataSource declaration:

<asp:ObjectDataSource ID='ObjectDataSource1'                        runat='server'                        SelectMethod='GetAllWithId'                       TypeName='BrokerageTransactions'>                       <SelectParameters>                           <asp:ControlParameter                                 ControlID='ddlBrokerageDetails'                                          Name='brokid'                                PropertyName='SelectedValue'                               Type='Object' />                       </SelectParameters> </asp:ObjectDataSource> 

Thanks, X

  • 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-10T20:11:29+00:00Added an answer on May 10, 2026 at 8:11 pm

    When you are using an ObjectDataSource (or any other *DataSource), you set the DataSourceID for your GridView, not the DataSource. The DataSourceID should be whatever the ID of your ObjectDataSource is. If you provide the declaration of your ObjectDataSource, I might be able to help more.

    As to why your DataSource is null in your Sorting event, it’s because you set the DataSource, sent the page to the client, clicked on a column header, posted back to the server, and now have a brand new GridView instance that has never had its DataSource property set. The old GridView instance (and the data table you bound to) have been thrown away.

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

Sidebar

Ask A Question

Stats

  • Questions 80k
  • Answers 80k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As a short answer I would say: Yes, it is… May 11, 2026 at 4:16 pm
  • Editorial Team
    Editorial Team added an answer Instead of copying the file, why not just move it… May 11, 2026 at 4:16 pm
  • Editorial Team
    Editorial Team added an answer You'll have to use the win32 ReadProcessMemory API - there's… May 11, 2026 at 4:16 pm

Related Questions

I'm new to MVC, and am not following how you'd do paging and sorting
I currently have a Gridview that displays TypeID , Name , Description. I would
I have an ASP.NET GridView which has columns that look like this: | Foo
I currently have an ASP.NET GridView that displays a few columns to the user

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.