Hi,
I tried the update query to update the details in grid control with below code.But I got the error(Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index). when i click the update button.
My Code:
GridDataItem updateitem = (e.Item as GridDataItem);
string id = updateitem.OwnerTableView.DataKeyValues[updateitem.ItemIndex]["userid"].ToString();//Error Comes in this line
TextBox txtuname = (updateitem)["userid"].Controls[0] as TextBox;
TextBox txtdob = (updateitem)["dateofjoin"].Controls[0] as TextBox;
TextBox txtpwd = (updateitem)["pwd"].Controls[0] as TextBox;
string unameupdate = txtuname.Text;
string dobupdate = txtdob.Text;
string pwdupdate = txtpwd.Text;
conn.Open();
string updateaccount = "update login set userid ='" + unameupdate + "',pwd ='" + pwdupdate + "',cpwd ='" + pwdupdate + "',dateofjoin ='" + dobupdate + "' where userid ='" + id + "'";
cmd = new MySqlCommand(updateaccount, conn);
cmd.ExecuteNonQuery();
conn.Close();
showaccountuser();
I tried the update query to update the details in grid control with below code.But I got the error(Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index). when i click the update button.
My Code:
GridDataItem updateitem = (e.Item as GridDataItem);
string id = updateitem.OwnerTableView.DataKeyValues[updateitem.ItemIndex]["userid"].ToString();//Error Comes in this line
TextBox txtuname = (updateitem)["userid"].Controls[0] as TextBox;
TextBox txtdob = (updateitem)["dateofjoin"].Controls[0] as TextBox;
TextBox txtpwd = (updateitem)["pwd"].Controls[0] as TextBox;
string unameupdate = txtuname.Text;
string dobupdate = txtdob.Text;
string pwdupdate = txtpwd.Text;
conn.Open();
string updateaccount = "update login set userid ='" + unameupdate + "',pwd ='" + pwdupdate + "',cpwd ='" + pwdupdate + "',dateofjoin ='" + dobupdate + "' where userid ='" + id + "'";
cmd = new MySqlCommand(updateaccount, conn);
cmd.ExecuteNonQuery();
conn.Close();
showaccountuser();