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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:25:34+00:00 2026-06-05T03:25:34+00:00

I am writing an application that will display database queries. There are different tables

  • 0

I am writing an application that will display database queries. There are different tables and I would like to be able to choose between them with radio buttons. This is currently working properly, but now I am trying to figure out how to format the data repeater based on which table will be displayed (there are different numbers of columns, in a different order, etc.) I got the header to format successfully since it is just basic HTML, but the item template requires using asp inline code, which I believe is causing the problem.

relevant code from code-behind:

protected string showDataTableItemTemplate()
{
    string itemTemplateText = string.Empty;

    if (tableSelection == "parts")
    {
        itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.PartNumber\") %></td>";
        itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.Description\") %></td>";

    }
    else if (tableSelection == "package")
    {
        itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.PackageNumber\") %></td>";
        itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.Description\") %></td>";

    }
    else if (tableSelection == "product")
    {
        itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.ProductNumber\") %></td>";
        itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.Description\") %></td>";
    }
    return itemTemplateText;
}

Then I just have the literal defined like this in the aspx:

<asp:Literal runat="server" Text='<%#showDataTableItemTemplate() %>'></asp:Literal>

Is there another way to do this?

EDIT: I now have the following:

    protected void DataRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        LiteralControl itemTemplateLiteral = new LiteralControl();
        itemTemplateLiteral = (LiteralControl)FindControl("itemTemplate");
        string itemTemplateText = string.Empty;

        if (tableSelection == "parts")
        {
            itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.PartNumber\") %></td>";
            itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.Description\") %></td>";

        }
        else if (tableSelection == "package")
        {
            itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.PackageNumber\") %></td>";
            itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.Description\") %></td>";

        }
        else if (tableSelection == "product")
        {
            itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.ProductNumber\") %></td>";
            itemTemplateText += "<td><%# DataBinder.Eval(Container,\"DataItem.Description\") %></td>";

        }
        itemTemplateLiteral.Text = itemTemplateText;
    }

The compiler keeps telling me that there is an Object reference not set to an instance of an object. error. Also, Am I correct in trying to set the Text property still? (Wasn’t that what I was trying to avoid by using this method?)

  • 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-05T03:25:35+00:00Added an answer on June 5, 2026 at 3:25 am

    You should have an event handler for the OnItemDataBound event of the template control and in it use FindControl to locate the Literal control and assign values to it using the e.Item.DataItem.

    What your current code is doing is simply assigning strings to the literal – these will not be evaluated as part of page markup because they are not part of the markup.

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

Sidebar

Related Questions

I am writing an application that will display serial/USB data at a rate of
I'm writing a program using jdbc that will be an interface to database(smth like
I am writing my own SMS application that will display a toast of my
I'm writing an application that will have an option to run on Windows Startup.
I'm writing an application that will create difficult passwords for the user. The user
I'm writing an application that will add users to Active Directory. I'm trying to
I am writing a PHP application that will have the ability to edit settings
I'm writing a console application that will be deployed with an installation of an
I am writing a Silverlight application that will be both reading and writing data
I'm writing a wrapper application that will be used to provide an abstraction layer

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.