PDA

View Full Version : Index was out of range



faramarz_s
شنبه 29 شهریور 1382, 10:37 صبح
string name = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
string family = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
string fn = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
string shsh1 = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
string born_Date = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
string Address = ((TextBox)e.Item.Cells[6].Controls[0]).Text;
string tel= ((TextBox)e.Item.Cells[7].Controls[0]).Text;
string postcode= ((TextBox)e.Item.Cells[8].Controls[0]).Text;
string faf= ((TextBox)e.Item.Cells[9].Controls[0]).Text;
string memoir = ((TextBox)e.Item.Cells[10].Controls[0]).Text;
string degree= ((TextBox)e.Item.Cells[11].Controls[0]).Text;
string un = ((TextBox)e.Item.Cells[12].Controls[0]).Text;
string gd = ((TextBox)e.Item.Cells[13].Controls[0]).Text;
string po = ((TextBox)e.Item.Cells[14].Controls[0]).Text;
string mp = ((TextBox)e.Item.Cells[15].Controls[0]).Text;
string picture = ((TextBox)e.Item.Cells[16].Controls[0]).Text;
string smd= ((TextBox)e.Item.Cells[17].Controls[0]).Text;
string emd = ((TextBox)e.Item.Cells[18].Controls[0]).Text;

SqlConnection conn =
new SqlConnection("server=(local);uid=sa;pwd=yaali;database=MDB;");

// Prepare the command text
String strCmd = "UPDATE tblCustomer SET name=N'"+
name+ "'," + "family=N'" + family+ "'," + "fn='" + fn+ "'"+
" WHERE name='" + name+"'";


SqlCommand cmd = new SqlCommand(strCmd, conn);

conn.Open();
cmd.ExecuteNonQuery();
conn.Close();

// Reset the edit mode for the current item
DataGrid1.EditItemIndex = -1;

// create data source again.........
bindToDatGrid();


Specified argument was out of the range of valid values. Parameter name: index
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: Specified argument was out of the range of valid values. Parameter name: index

Source Error:


Line 80: string family = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
Line 81: string fn = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
Line 82: string shsh1 = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
Line 83: string born_Date = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
Line 84: string Address = ((TextBox)e.Item.Cells[6].Controls[0]).Text;

Vahid_Nasiri
شنبه 29 شهریور 1382, 14:44 عصر
ببین این مشکل را حل می کند؟


(int)e.Item.ItemIndex-1

faramarz_s
شنبه 29 شهریور 1382, 21:31 عصر
اگر امکان دارد یه توضیحی هم بفرمایید :wink:

Vahid_Nasiri
یک شنبه 30 شهریور 1382, 01:06 صبح
خطا مربوط به این بود که اندیس تعریف شده برای آرایه از حدبالایی آن تجاوز کرده بود. یکی از آن کم کردیم تا مشکل حل شود.

faramarz_s
چهارشنبه 02 مهر 1382, 21:34 عصر
من به دلیل برخورد دوباره به مشکل ایندکس پست اول ر ا ویرایش کردم .
حالا مشکل چیست؟
:wink:

Vahid_Nasiri
پنج شنبه 03 مهر 1382, 11:19 صبح
آیا قبل از اینکه update را کلیک کنی اصلا داده ها به گرید بایند شده است؟ به نظر می رسد که اصلا این ستون ها وجود ندارند که این خطا را می دهد.