Skip to content

How to set accept in cell(2) after selecting in gridview

dhivya pm

Asked Apr 1, 2013, 10:01 PM EDT1 answer
Share
LinkedInX
i have to set status as accept,reject for customer,while registering status while be pending. i need ,if condition for this, which row is selected then corressponding event should change in database as accept or reject

Java
protected void Button2_Click(object sender, EventArgs e) {


        SqlCommand cmd = new SqlCommand("select * from Testing", OIMS_01);
    SqlDataAdapter ad = new SqlDataAdapter(cmd);
     DataSet ds = new DataSet();


   ad.Fill(ds);


    if (GridView1.SelectedRow != null)
    {
     ds.Tables(0).Rows(0).Item(0) = GridView1.SelectedRow.Cells(1).Text;
      ds.Tables(0).Rows(0).Item(1) = GridView1.SelectedRow.Cells(2).Text;
ds.Tables(0).Rows(0).Item(2) = "Accept";


    }
    else
    {
        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please select a row.')", true);
    }
    ad.Update(ds);
}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Vishal Gilbile
    0
    Hello Friend,
                   You could get the index no of the gridview row which is being currently selected by using the following line of code.

    int index = ((GridViewRow)((Button)sender).NamingContainer).RowIndex;

    then finally after getting the index no of the row you could easily change the data in the database to accept, reject or pending as per your scenario by firing update query.

    Hope that solves your problem.

    With Regards,
    Vishal Gilbile.
    0