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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:00:56+00:00 2026-05-14T02:00:56+00:00

SOLVED. Code has been edited to reflect solution. Given the following GridView : <asp:GridView

  • 0

SOLVED. Code has been edited to reflect solution.

Given the following GridView:

<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false" DataKeyNames="UniqueID"
        OnSelectedIndexChanging="GridView1_SelectedIndexChanging" >
<Columns>
    <asp:BoundField HeaderText="Remarks" DataField="Remarks" />
    <asp:TemplateField HeaderText="Listing">
    <ItemTemplate>
        <%# ShowListingTitle( Container.DataItem ) %>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField HeaderText="Amount" DataField="Amount" DataFormatString="{0:C}" />
</Columns>
</asp:GridView>

which refers to the following code-behind method:

protected String ShowListingTitle( object /* was DataRow */ row )
{
    Listing listing = ( Listing ) row;

    return NicelyFormattedString( listing.field1, listing.field2, ... );
}

The cast from DataRow to Listing was failing (cannot convert from DataRow to Listing) I’m certain the problem lies in what I’m passing from within the ItemTemplate, which is simply not the right reference to the current record from the LINQ to SQL data set that I’ve created, which looks like this:

private void PopulateGrid()
{
    using ( MyDataContext context = new MyDataContext() )
    {
        IQueryable < Listing > listings = from l in context.Listings where l.AccountID == myAccountID select l;

        GridView1.DataSource = listings;
        GridView1.DataBind();
    }
}
  • 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-05-14T02:00:56+00:00Added an answer on May 14, 2026 at 2:00 am

    IIRC, you should just be calling Container.DataItem, and that will be a Listing.

    Try it by doing <%# Container.DataItem.ToString() %> as a test.

    I havent used ASP.NET in years though, so memory might be rusty.

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

Sidebar

Related Questions

The problem mentioned below has been solved and code has been changed to reflect
Update : my problem has been solved, I updated the code source in my
I solved Problem 10 of Project Euler with the following code, which works through
I have a code like this, which is solved by me following a exercise
Update: this leak has been solved. If you are getting similar leaks and your
you will think: "This problem has been solved many, many times. So why doesn't
This question has been asked many times, but I tried every solution and none
In the following example code I illustrate how I solved passing the request from
Apologies if this has already been asked and solved but through numerous searches and
Hey most of my issue has been solved but i have little problem This

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.