Gridview单选按钮删除 [英] Gridview radio button Delete

查看:62
本文介绍了Gridview单选按钮删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我想在网格视图中删除选定的行,就像我在网格视图中选择单选按钮,并且如果我单击删除"按钮,则应删除记录.

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.

推荐答案

我可以为单选按钮分配字符串值吗?

我的代码就是这样

Can i assign string value to radiobutton

My code is like this

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


通常这是使用复选框完成的.请看一下这篇文章以了解如何做.如果愿意,可以用单选按钮替换复选框.
GridView一目了然 [
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.


将命令字段"作为一列放置一个删除并编写代码"按钮删除GridView_RowDeleting
中的记录
请参阅下面的代码...

//CommandName ="delete"
受保护的void GridView_RowDeleting(对象发送者,GridViewDeleteEventArgs e)
{
//找到选择了哪一行的行索引.
int行= e.RowIndex;
//删除临时行(或删除查询,该查询将从
中删除该行 //数据库
//这里的Temp是您的DataSet
Temp.Rows [row] .Delete();
//重新分配数据源
GridView3.DataSource = Temp;
GridView3.DataBind();
}
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();
}


这篇关于Gridview单选按钮删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆