السلام عليكم
لدى خطا دائما ما يتكرر مع استخدامى لل datagrid
لذا كنت ارجو ان يساعدنى احد حيث ان الخطا يقول
اقتباسSpecified argument was out of the range of valid values. Parameter name: indexDescription: 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
public void BindData()
{
string myconn= "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=test;" +
"UID=root;" +
"PASSWORD=;" +
"OPTION=3";
OdbcConnection Conn=new OdbcConnection(myconn);
OdbcCommand myCommand=new OdbcCommand("select UserID,UserName,F_Name,L_Name,Email from Users",Conn);
Conn.Open();
this.DataGrid1.DataSource=myCommand.ExecuteReader();
this.DataGrid1.DataBind();
Conn.Close();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex=-1;
string un,fn,ln,em;
string uid;
TableCell cell1 = (TableCell)e.Item.Controls[1];
uid = (string)((TextBox)cell1.Controls[1]).Text;
TableCell tc2=(TableCell)e.Item.Controls[2];
un=(string)((TextBox)tc2.Controls[1]).Text;
TableCell tc3=(TableCell)e.Item.Controls[3];
fn=((TextBox)tc3.Controls[1]).Text;
TableCell tc4=(TableCell)e.Item.Controls[4];
ln=((TextBox)tc4.Controls[1]).Text;
TableCell tc5=(TableCell)e.Item.Controls[5];
em=((TextBox)tc5.Controls[1]).Text;
string updatecomm="";
if(uid=="")//new one
{
updatecomm+= "INSERT INTO";
updatecomm += " Users VALUES ";
updatecomm += "('"+un+"','"+fn+"','"+ln+"',"+em+")";
}
else//edit
{
updatecomm+="update Users set";
updatecomm+="UserName='"+un+"',F_Name='"+fn+"',L_Name='"+ln+"' ,Email="+em+" ";
}
string myconn= "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=test;" +
"UID=root;" +
"PASSWORD=;" +
"OPTION=3";
OdbcConnection Conn=new OdbcConnection(myconn);
OdbcCommand Command=new OdbcCommand(updatecomm,Conn);
Conn.Open();
Command.ExecuteNonQuery();
Conn.Close();
BindData();الخطا فى هذا السطر
uid = (string)((TextBox)cell1.Controls[1]).Text;
ارجو المساعدة و جزاكم الله خيرا