[Solved] ASP.Net Error: Operator >= cannot be applied to operand of type string and string

akhter
 
on Dec 14, 2020 09:26 PM
981 Views

i am trying to set if else condition but it is giving me error

Operator '>=' cannot be applied to operand of type 'string' and 'string'

on below

        protected void OnCalculate(object sender, EventArgs e)
        {
            TextBox absent = sender as TextBox;

            GridViewRow row = absent.NamingContainer as GridViewRow;

            TextBox total = row.FindControl("txttotal") as TextBox;

            TextBox obtain = row.FindControl("txtobtain") as TextBox;
            DropDownList status = row.FindControl("ddlStatus") as DropDownList;

            DataTable dt = (DataTable)ViewState["dt"];
            dt.Rows[row.RowIndex]["txttotal"] = Convert.ToDecimal(total.Text.Trim());
            dt.Rows[row.RowIndex]["txtobtain"] = Convert.ToDecimal(obtain.Text.Trim());

            string a = Convert.ToString(obtain.Text);

            if ( a >= "90" )
            {
                status.SelectedValue = "2";
            }

            ViewState["dt"] = dt;
        }

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Dec 14, 2020 10:54 PM
akhter says:
    string a = Convert.ToString(obtain.Text);
 
    if ( a >= "90" )

The greater and the less operator should apply when you compare numbers.

You can not apply arithmetic operators to strings.

Convert the string number to integer value before compare.

int a = Convert.ToInt32(obtain.Text);
if ( a >= 90 )
{
    status.SelectedValue = "2";
}