Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,
I would like to delete the selected row in the grid view like if i select radio button in the grid view and if i click delete button the record should be deleted. How can i implement this.
Posted

Can i assign string value to radiobutton

My code is like this

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        //string empid;
        foreach(GridViewRow r in GridView1.Rows)
        {
            RadioButton rb = new RadioButton();
//empid = rb.tostring();
            rb = (RadioButton)r.FindControl("Radio1");
            if (rb.Checked)
            {
                cmd = new SqlCommand("empdel", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@CustomerID", SqlDbType.Int);
              //  cmd.Parameters["@CustomerID"].Value = empid;
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                GridView1.EditIndex = -1;
                BindGrid();
            }
        }
    }

can any one modify and send
 
Share this answer
 
Generally this is done using checkbox... Have a look at this article to get how to do it. You can replace checkbox with radio button if you like.
GridView all in one[^]

If needed more, there are few more articles here in CodeProject itself, just use the CP Search.
 
Share this answer
 
Take a Command Field as a one column and place a Button say Delete and Write the Code for deleting the record in GridView_RowDeleting

Refer below code...

//CommandName="delete"
protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//finding the row index of which row is selected.
int row = e.RowIndex;
//deleteing the temp row(or your delete query that will delete the row from
//the database
// Here Temp is your DataSet
Temp.Rows[row].Delete();
//reassigning the datasource
GridView3.DataSource = Temp;
GridView3.DataBind();
}
 
Share this answer
 
After selection of radio button and put the below code in delete button click event

foreach (GridViewRow row in gridview.Rows)
{
RadioButton rbn=new RadioButton();

rbn=(RadioButton)row.findcontrol("radiobutton id");

if(rbn.selected)
{
//put your delete code here
}
}
 
Share this answer
 
Got the one i required.

Thanking you,
Dorababu
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900