PDA

View Full Version : سوال: خطای startIndex cannot be larger than length of string.



bftarane
یک شنبه 08 بهمن 1391, 12:04 عصر
سلام. من از پست 9 این لینک برای ایجاد منوی داینامیک استفاده کردم
http://barnamenevis.org/showthread.php?215065
حالا وقتی که منو خالی هست و هیچ آیتمی توش درج نشده
موقع اجرا با این ارور مواجه میشم

startIndex cannot be larger than length of string.
Parameter name: startIndex
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string.
Parameter name: startIndex

Source Error:


Line 27: da.SelectCommand = select;
Line 28: da.Fill(dt);
Line 29: lit.Text = " <ul class=\"sf-menu dropdown\">" + menuMaker(0).Substring(5);
Line 30:
Line 31:

اومدم به شکل زیر تغییر دادم

if (menuMaker(0) != null)
{


lit.Text = " <ul class=\"sf-menu dropdown\">" + menuMaker(0).Substring(5);
}

بازم همون ارور رو دریافت می کنم
خواهش می کنم راهنمایی کنید چطور این ارور رو رفع کنم؟

taghi.km
یک شنبه 08 بهمن 1391, 12:37 عصر
سلام
ببینید به جای این خط if (menuMaker(0) != null)
از این خط می تمونی استفاده کنی if (menuMaker(0).length > 0)

bftarane
یک شنبه 08 بهمن 1391, 13:55 عصر
:تشویق: راهنمایی تون عالی بود.