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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:28:49+00:00 2026-06-08T01:28:49+00:00

I am using a LinqDataSource and a FormView with paging enabled on an ASP.NET

  • 0

I am using a LinqDataSource and a FormView with paging enabled on an ASP.NET page. I am trying to access the FormView’s DataItem property on PageLoad and I have no trouble on the first page load, but as soon as I use the Next/Prev page button (causing a postback) on the FormView the DataItem property is null, even if there a record showing in the FormView. Any ideas why it works fine on the first page load but not on a postback?

If you’re curious what my PageLoad event looks like, here it is:

protected void Page_Load(object sender, EventArgs e)
{
    Label lbl = (Label)fvData.FindControl("AREALabel");
    if (fvData.DataItem != null && lbl != null)
    {
        INSTRUMENT_LOOP_DESCRIPTION record = (INSTRUMENT_LOOP_DESCRIPTION)fvData.DataItem;
        var area = db.AREAs.SingleOrDefault(q => q.AREA1 == record.AREA);
        if (area != null)
            lbl.Text = area.AREA_NAME;
    }
}
  • 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-08T01:28:51+00:00Added an answer on June 8, 2026 at 1:28 am

    The object you bind to any data-bound control won’t be persisted in the page’s ViewState

    Therefore, on subsequent posts the DataItem property will be null unless you re-bind the control

    This property will contain a reference to the object when the control is bound.

    Usually you would need to access this property if you want to do something when the objects is bound, so you need to react to the DataBound event

    Example:

    Output

    enter image description here

    Code behind

    protected void ds_DataBound(object sender, EventArgs e)
    {
        var d = this.fv.DataItem as employee;
        this.lbl.Text = d.lname;
    }
    

    ASPX

        <asp:LinqDataSource ID="lds" runat="server"
            ContextTypeName="DataClassesDataContext"
            TableName="employees" 
        >
    
        </asp:LinqDataSource>
        <asp:FormView runat="server" ID="fv" DataSourceID="lds" AllowPaging="true" 
            OnDataBound="ds_DataBound">
            <ItemTemplate>
                <asp:TextBox Text='<%# Bind("fname") %>' runat="server" ID="txt" />
            </ItemTemplate>
        </asp:FormView>
        <br />
        <asp:Label ID="lbl" runat="server" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using LinqDataSource like that: <asp:LinqDataSource ID=LinqDataSource3 runat=server OnSelecting=LinqDataSource3_OnSelecting> </asp:LinqDataSource> And I have ASPxGridView
I have a fairly simple form: <asp:FormView> <EditItemTemplate> <asp:LoginView> <RoleGroups> <asp:RoleGroup roles=Blah> <ContentTemplate> <!--
i am using LinqDataSource and a gridview control and my paging/sorting works fine but
I'm using a standard GridView with a LinqDataSource. The user can sort and page
I'm trying to update my LinqDataSource Object through my GridPanel <asp:LinqDataSource ID=LinqDataSource1 runat=server ContextTypeName=IntraNET_Prototype.IntraNetEntities
I have the following code in my user control: <asp:LinqDataSource ID=myLinqDataSource runat=server AutoSort=true ContextTypeName=MyDBContext
I have a gridview that is using a LinqDataSource for it's datasource. I've added
i have a GridView with LinqDataSource. im using the following technique to populate a
I have a simple wizard generated query in a LinqDataSource like this: <asp:LinqDataSource ID=EvaluationsData
I am trying to use LinqDataSource instead of using the SQL dataset. Currently, if

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.