Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ฟ้อง error Must be non-negative and less than the size of the collection ค่ะ asp.net c#



 

ฟ้อง error Must be non-negative and less than the size of the collection ค่ะ asp.net c#

 



Topic : 088877



โพสกระทู้ ( 301 )
บทความ ( 0 )



สถานะออฟไลน์




ฟ้อง error ค่ะ Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

อ้างถึง gridview 2 ตัว ค่ะ สามารถ เขียนแบบนี้ได้ไหมค่ะ

Code (C#)
  int n;
             int i;
             for (i = 0; i <= GridView1.Rows.Count - 1; i++)
             {

             
             for (n = 0; n <= GridView2.Rows.Count - 1; n++)
             {
                 
                     double sumtotal2 = 0.00;
                     double sumtotal3 = 0.00;
                     //GridView2
                     string total= ((Label)GridView2.Rows[n].FindControl("total")).Text.Trim(); 
                     string Idta = ((Label)GridView2.Rows[n].FindControl("Idta")).Text.Trim();
                     string Idqu = ((Label)GridView2.Rows[n].FindControl("Idqu")).Text.Trim();
                     //GridView1
                     string Money = ((Label)GridView1.Rows[n].FindControl("Money")).Text.Trim();
                     string Idta2 = ((Label)GridView1.Rows[n].FindControl("Idta")).Text.Trim();
                     string Idqu2 = ((Label)GridView1.Rows[n].FindControl("Idqu")).Text.Trim();
                   if (Idta == Idta2  && Idqu2 == Idqu2)
                {    
               
                         ((Label)GridView1.Rows[n].FindControl("Money")).Text =                               ((Label)GridView2.Rows[n].FindControl("totalvol")).Text.Trim();

                     }


                 }


ฟ้อง error ตรง

Code (C#)
string Money = ((Label)GridView1.Rows[n].FindControl("Money")).Text.Trim();
                   
string Id_tax2 = ((Label)GridView1.Rows[n].FindControl("Id_tax")).Text.Trim();
                    
string Id_quota2 = ((Label)GridView1.Rows[n].FindControl("Id_quota")).Text.Trim();


ฟ้องว่า Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index เพราะ อะไรหรอ ค่ะ มีวิธีแก้อย่างไรค่ะ



Tag : .NET, Ms SQL Server 2008, C#









ประวัติการแก้ไข
2013-01-07 12:05:53
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-01-07 12:01:39 By : mushroomsn View : 1406 Reply : 2
 

 

No. 1

Guest


- if (Idta == Idta2 && Idqu2 == Idqu2) ???

- วนลูป i แล้วเอา i ไปใช้ตรงไหน

- for (i = 0; i <= GridView1.Rows.Count - 1; i++) แก้เป็น for (i = 0; i < GridView1.Rows.Count; i++)

- for (n = 0; n <= GridView2.Rows.Count - 1; n++) แก้เป็น for (n = 0; n < GridView2.Rows.Count; n++)

-
Code (C#)
if (n < GridView1.Rows.Count)
{
   string Money = ((Label)GridView1.Rows[n].FindControl("Money")).Text.Trim();
                   
   string Id_tax2 = ((Label)GridView1.Rows[n].FindControl("Id_tax")).Text.Trim();
                    
   string Id_quota2 = ((Label)GridView1.Rows[n].FindControl("Id_quota")).Text.Trim();

   if (Idta == Idta2  && Idqu == Idqu2)
   {   
      ((Label)GridView1.Rows[n].FindControl("Money")).Text = ((Label)GridView2.Rows[n].FindControl("totalvol")).Text.Trim();
   }
}







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-07 14:39:16 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 2



โพสกระทู้ ( 301 )
บทความ ( 0 )



สถานะออฟไลน์


ค่ะ ขอบคุณค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-07 15:41:06 By : mushroomsn
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ฟ้อง error Must be non-negative and less than the size of the collection ค่ะ asp.net c#
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่