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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:43:52+00:00 2026-05-25T12:43:52+00:00

I am trying to display 1. Red if the TimeReceived is Null, (or) 2.

  • 0

I am trying to display
1. Red if the TimeReceived is Null, (or)
2. Amber when Time Received is not null and Time Read is Null (Or)
3. Green When Time read is not null

It throws an error

Input string was not in a correct format. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error: 


Line 86:         {
Line 87:             Image img = (Image)e.Row.FindControl("image1");
Line 88:             switch (int.Parse(e.Row.Cells[1].Text))
Line 89:             {
Line 90:                 case 0:

Where I am going wrong, how can I display image based on the condition. I think I haven’t done the rowdatabound correctly. Please help.

  • 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-25T12:43:52+00:00Added an answer on May 25, 2026 at 12:43 pm

    You are probably trying to parse a null or empty string as an int. Change your int.Parse line to:

    switch (int.Parse(string.IsNullOrEmpty(e.Row.Cells[1].Text)?"0":e.Row.Cells[1].Text))
    

    UPDATE: Now that you have pasted the actual image of how the Grid looks, I think Joel Etherton is right, you are trying to parse a Date as an integer. Cell[1] (assuming you don’t have any invisible columns to the left) is a Date, not an integer so when you try int.Parse throws the exception because it cannot parse it. Also, according to your conditions, your MyGrid_RowDataBound logic is incorrect. Try changing your implementation to this.

    protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Image img = (Image)e.Row.FindControl("image1");
            //condition for red image; Neither TimeReceived and TimeRead are populated
            if(string.IsNullOrEmpty(e.Row.Cells[1].Text) &&  
               string.IsNullOrEmpty(e.Row.Cells[2].Text))
            {
                img.ImageUrl = "/images/Red.gif";
                img.Visible = true;
            }
            //condition for amber image; TimeReceived not null and TimeRead is null
            else if (!string.IsNullOrEmpty(e.Row.Cells[1].Text) &&  
                     string.IsNullOrEmpty(e.Row.Cells[2].Text))
            {
                img.ImageUrl = "/images/Amber.gif";
                img.Visible = true;
            }
            //condition for green image; TimeReceived not null and TimeRead not null
            else if (!string.IsNullOrEmpty(e.Row.Cells[1].Text) &&  
                     !string.IsNullOrEmpty(e.Row.Cells[2].Text))
            {
               img.ImageUrl = "/images/Green.gif";
               img.Visible = true;
            }
            else //default case
            {
                img.Visible = false;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I am trying to display an image from C:\temp. Here's the code: string root
I am currently trying to display the number and date(string format) of a json
I am trying to understand why my login form does not display the validation
When trying to display a byte stream from HLDS (Half-Life Dedicated Server) in a
I am trying to display a sphere in PGF/TikZ to illustrate the idea of
I am trying to display different divs depending on a selection from a drop
I am trying to perform several image manipulations using OpenGL ES 2.0 and display
I have been trying to solve this problem for a while, could not find
I am trying to display an absolutely positioned div inside floating div. Here is

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.