n when that button is clickd i want to delete that particular record from gridview...
runat="server" Text="mydelete" />
n when that button is clickd i want to delete that particular record from gridview...
i did in .cs
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
Label sid = (Label)GridView1.Rows[index].FindControl("lblsid");
Label fid = (Label)GridView1.Rows[index].FindControl("lblfromId");
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
Label sid = (Label)GridView1.Rows[index].FindControl("lblsid");
Label fid = (Label)GridView1.Rows[index].FindControl("lblfromId");
if (e.CommandName == "mydelete")
{
scrapobj.Open();
string q = "Delete from scraps where sid=@sid AND fromId=@fromId";
SqlCommand comm = new SqlCommand(q, scrapobj);
comm.Parameters.AddWithValue("@sid", Convert.ToInt32(sid.Text.ToString()));
comm.Parameters.AddWithValue("@fromId", p.profile_Id);
comm.ExecuteNonQuery();
scrapobj.Close();
GridView1.DataBind();
}
but it gives this error:
Invalid postback or callback argument. Event validation is enabled using
{
scrapobj.Open();
string q = "Delete from scraps where sid=@sid AND fromId=@fromId";
SqlCommand comm = new SqlCommand(q, scrapobj);
comm.Parameters.AddWithValue("@sid", Convert.ToInt32(sid.Text.ToString()));
comm.Parameters.AddWithValue("@fromId", p.profile_Id);
comm.ExecuteNonQuery();
scrapobj.Close();
GridView1.DataBind();
}
but it gives this error:

Amit ChoudharyPosted Mar 15, 2010, 1:38 AM
you have two option to solve this problem..
1. Put you whole code inside the page_load event under following condition
if(!page.Ispostback)
{
//Your code will go here
}
OR
2. set page attribute EnableEventValidation="false" like this.
2nd option will solve your problem but CLR concerned this as unsafe sate of events.
Please mark my answer i know your problem will get solved.