Link to home
Start Free TrialLog in
Avatar of riskyricky1972
riskyricky1972

asked on

asp c#, IE 6.0

I have the following usercontrol. everything works fine except this one

public int producthowmany
    {
        get {txtproducthowmany.Text; }
        set { txtproducthowmany.Text = value; }
    }

I tried to call that and it is always saying that string cannot convert to integer. so I put
Int32.Parse() and it still does not work. Any ideas how to fixed it?




 public string productname
    {
        get { return txtproductname.Text; }
        set { txtproductname.Text = value; }
    }
    public string productdescription
    {
        get { return txtproductdescription.Text; }
        set { txtproductdescription.Text = value; }
    }
    public int producthowmany
    {
        get { return Int32.Parse(txtproducthowmany.Text); }
        set { txtproducthowmany.Text = Int32.Parse(value); }
    }
    public int productcondition
    {
        get { return ddlproductcondition.SelectedItem.Text; }
        set { ddlproductcondition.SelectedItem.Text = value; }
    }
    public float productpriceperunit
    {
        get { return txtproducthowmuch.Text; }
        set { txtproducthowmuch.Text = value; }
    }
Avatar of sabeesh
sabeesh
Flag of United States of America image

this is failed when the textbox value is null or string.empty

you can check the value before parsing

 public int producthowmany
    {
        get {
int i = 0;
if (txtproducthowmany.Text.Length > 0)
 i =  Int32.Parse(txtproducthowmany.Text);
return i;
}
        set { txtproducthowmany.Text = Int32.Parse(value); }
    }
or try this also

 public int producthowmany
    {
        get {
int i = 0;

 i =  int.TryParse(txtproducthowmany.Text, out i); //check the syntex
return i;
}
        set { txtproducthowmany.Text = Int32.Parse(value); }
    }

Avatar of riskyricky1972
riskyricky1972

ASKER

error point to set { txtproducthowmany.Text = Int32.Parse(value); }
  to say that it can not convert from string to int.
textProductthowmany.Text is a string value so cannot assign a int value.
try like this
textProductthowmany.Text = value.ToString()
and now I have dropdown.
and failed me again.

 if (ddlproductcondition.SelectedItem.Selected.Length > 0 )
ASKER CERTIFIED SOLUTION
Avatar of sabeesh
sabeesh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial