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; }
    }
riskyricky1972Asked:
Who is Participating?
 
sabeeshConnect With a Mentor Commented:
use this for condition
if(ddlproductcondition.SelectedIndex >= 0)
0
 
sabeeshCommented:
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); }
    }
0
 
sabeeshCommented:
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); }
    }

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

 if (ddlproductcondition.SelectedItem.Selected.Length > 0 )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.