PDA

View Full Version : سوال در مورد برطرف نمودن Exception در Asp.net



saeid329
جمعه 08 فروردین 1393, 21:53 عصر
با سلام خدمت همه ی دوستان عزیزم در سایت برنامه نویس
من ی کد دارم که اکسپشن میده لطفا یک نفر منو راهنمایی کنه

string name = ((Label)DataList1.Controls[0].FindControl("nameLabel")).Text;

این خط کد بالا به این صورت اکسپشن میده
Object reference not set to an instance of an object.


int price = int.Parse(((Label)DataList1.Controls[0].FindControl("priceLabel")).Text);
این خط کد بالا به این صورت اکسپشن میده
Input string was not in a correct format

string PicUrl = ((Label)DataList1.Controls[0].FindControl("PicUrlLabel")).Text;
string isbn = Request.QueryString["isbn"];






if (Profile.Cart == null)
{
Profile.Cart = new rayaneh.commerce.shopingcart();


}


Profile.Cart.insert(isbn, price, 1, name, PicUrl);
Server.Transfer("Default.aspx");

در ضمن من این متغیر ها رو هم به صورت زیر در یک کلاس تعریف کردم و اون کلاس رو به کدم هم اضافه کردم

public class cartitem
{
private string _title;
private int _price;
private string _name;
private string _PicUrl;
private string _isbn;
private int _linetotal;
private int _quantity;


public void New()
{
}
public void New(string name, string isbn, int price, string PicUrl, int quantity)
{
_title = title;
_price = price;
_PicUrl = PicUrl;
_name = name;
_isbn = isbn;
_quantity = quantity;


_linetotal = quantity * price;
}
public string name
{
get
{
return _name;
}
set
{
_name = value;
}
}






public string title
{
get
{
return _title;
}
set
{
_title = value;
}
}








public int price
{
get
{
return _price;
}
set
{
_price = value;
}
}
public string isbn
{
get
{
return _isbn;
}
set
{
_isbn = value;
}
}
public string PicUrl
{
get
{
return _PicUrl;
}
set
{
_PicUrl = value;
}
}
public int quantity
{
get
{
return _quantity;
}
set
{
_quantity = value;
}
}
public int linetotal
{
get
{
return _quantity * _price;
}
}







}


لطفا یک نفر به من بگه که چه تغییری در کدم بدم که این اکسپشن ها از بین بره و برنامم به درستی کار کنه و گه نه خودم میتونم ی ترای کچ براش بنویسم
میخوام این اکسپشن نیاد و کدم اجرا بشه چه تغییری در کد بدم

mRizvandi
شنبه 09 فروردین 1393, 00:05 صبح
کد DataList1 رو بذارید.
به نظر میاد که nameLabel و priceLabel وجود ندارد، یا در شرایطی که هنوز به وجود نیامده اند می خواهید دسترسی پیدا کنید.