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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:14:36+00:00 2026-05-16T08:14:36+00:00

I’m a bit lost here with how the ListView works. When my ListView is

  • 0

I’m a bit lost here with how the ListView works.

When my ListView is created I do some coloring depending of the data in the result set.

protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
    DataRow myRow;
    DataRowView myRowView;
    myRowView = (DataRowView)e.Item.DataItem;
    myRow = myRowView.Row;
    HtmlTableRow myTR = (HtmlTableRow)e.Item.FindControl("trRow");
    HtmlTableCell myTC = (HtmlTableCell)e.Item.FindControl("tdCell");

    Label myCB = (Label)e.Item.FindControl("ResultLabel1");
    if (myRow["Result"].ToString().Equals("true"))
        myTC.Style.Value = "background-color:#00FF00;color: #000000;";
    else
        myTC.Style.Value = "background-color:#FF0000;color: #000000;";
}

The ListView has a pager and that is causing a postback to ItemCreated and I cant reach the dataRow again.

Any suggestion how to deal with this so I can handle postbacks?

UPDATE:
I changed the code to read the actual value of the Label called ResultLabel1 which is True/False but it returns back an empty string.. Thought this was better than reading the the result from the result from the DataSet. Can anyone see whats wrong?

Code:

        protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
    {
        HtmlTableRow myTR = (HtmlTableRow)e.Item.FindControl("trRow");
        HtmlTableCell myTC = (HtmlTableCell)e.Item.FindControl("tdCell");

        // Retrieve the current item.
        ListViewItem item = e.Item;

        // Verify if the item is a data item.
        if (item.ItemType == ListViewItemType.DataItem)
        {
            // Get the Label ResultLabel1 control in the item.
            Label myCB = (Label)item.FindControl("ResultLabel1");


            if (myCB.Text.Equals("True"))
                myTC.Style.Value = "background-color:#00FF00;color: #000000;";
            else
                myTC.Style.Value = "background-color:#FF0000;color: #000000;";

        }
    }

ASP.NET:

            <ItemTemplate>
            <tr id="trRow" runat="server" style="">
                <td>
                    <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                </td>
                <td>
                    <asp:Label ID="DateTime_StartLabel" runat="server" 
                        Text='<%# Eval("DateTime_Start") %>' />
                </td>
                <td>
                    <asp:Label ID="DateTime_EndLabel" runat="server" 
                        Text='<%# Eval("DateTime_End") %>' />
                </td>
                <td>
                    <asp:Label ID="TestCaseNameLabel" runat="server" 
                        Text='<%# Eval("TestCaseName") %>' />
                </td>
                <td>
                    <asp:Label ID="ModelNameLabel" runat="server" Text='<%# Eval("ModelName") %>' />
                </td>
                <td id="tdCell" runat="server">
                    <asp:Label ID="ResultLabel1" runat="server" 
                        Text='<%# Eval("Result") %>' />
                </td>
            </tr>
        </ItemTemplate>
  • 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-16T08:14:37+00:00Added an answer on May 16, 2026 at 8:14 am

    If you’re doing this colouring as a result of data binding, you might be better handling the ItemDataBound event instead of ItemCreated.

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

Sidebar

Related Questions

No related questions found

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.