I have a big mistake in rowcommand. I have a button field with commandname "add". When I click it the code doesn't fire the first time but click it again and the code fires!
if (e.CommandName == "add")
{
DataClassesDataContext db = new DataClassesDataContext();
int ii = int.Parse(e.CommandArgument.ToString());
int num = int.Parse(((TextBox)GridView1.Rows[ii].FindControl("TextBox2")).Text);
string id = GridView1.Rows[ii].Cells[0].Text;
temp t = new temp();
t.tedad = num;
t.username = Session["username"].ToString();
db.temps.InsertOnSubmit(t);
db.SubmitChanges();
}
rowcommand dose not fire when clicking the first time!
I figured out the issue, I was using
GridView_RowCreatedwhich was causing the problem, instead I usedGridView_RowDataBoundwhich solved the problem for me.or check that if you are binding the datagrid in not post back .