?
Solved

asp c#, IE 6.0

Posted on 2007-08-06
6
Medium Priority
?
213 Views
Last Modified: 2013-11-05
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; }
    }
0
Comment
Question by:riskyricky1972
  • 4
  • 2
6 Comments
 
LVL 8

Expert Comment

by:sabeesh
ID: 19642631
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
 
LVL 8

Expert Comment

by:sabeesh
ID: 19642638
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
 

Author Comment

by:riskyricky1972
ID: 19643463
error point to set { txtproducthowmany.Text = Int32.Parse(value); }
  to say that it can not convert from string to int.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Expert Comment

by:sabeesh
ID: 19645212
textProductthowmany.Text is a string value so cannot assign a int value.
try like this
textProductthowmany.Text = value.ToString()
0
 

Author Comment

by:riskyricky1972
ID: 19648079
and now I have dropdown.
and failed me again.

 if (ddlproductcondition.SelectedItem.Selected.Length > 0 )
0
 
LVL 8

Accepted Solution

by:
sabeesh earned 2000 total points
ID: 19648298
use this for condition
if(ddlproductcondition.SelectedIndex >= 0)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question