Datagrid单选按钮 [英] Datagrid radio button

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

问题描述

我有数据网格,我在数据网格中有两个单选按钮,即批准或拒绝,还有数据网格中的一个按钮,即提交



我想做的是当选择批准按钮并单击数据网格中的提交按钮一行时,我希望该行的数据存储在数据库中,其中Isactive为1,并且该行应从数据网格中删除,但是细节必须存储在数据库。



类似地,当选择拒绝按钮并单击datagrid中的提交按钮时,该行的数据应存储在Isactive为0的数据库中,并且行应该从数据网格中删除



详细信息必须存储在数据库中。



isActive 未在数据库中更新



有人可以告诉我我的代码中有什么问题吗?以下是我试过的C#代码..

I have data grid and I have two radio buttons in the datagrid i.e approve or reject and also one button in datagrid i.e submit

what i want to do is when approved button is selected and submit button in the datagrid is clicked for one row I want the data of that row to be stored in the database with Isactive as 1 and the row should be deleted from the datagrid, but details must be stored in the database.

Similarly when the reject button is selected and submit button in datagrid is clicked,the data of that row should be stored in the database with Isactive as 0 and the row should be deleted from the datagrid

details must be stored in the database.

The isActive is not updating in the database

Can someone please tell me whats wrong in my code? The below is my C# code that i tried..

protected void submit(object sender, EventArgs e)
{
    // *Get the Gridview Row* //
    DataGridItem drow = (DataGridItem)(sender as Control).Parent.Parent;

    RadioButton rbpApprove = (RadioButton)drow.FindControl("rbtnapprove");
    RadioButton rbpReject = (RadioButton)drow.FindControl("rbtnreject");

    if (rbpApprove.Checked == true)
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand("Update table set IsActive= 0 ", conn);

        cmd.ExecuteNonQuery();
        conn.Close();        
    }
    else if (rbpReject.Checked == true)
    {
        conn.Open();
        SqlCommand cmd = new SqlCommand("Update table set IsActive= 1", conn);
        cmd.ExecuteNonQuery();
        conn.Close();
    }


    string empid = dgi.Cells[0].Text;
    string employeename = dgi.Cells[2].Text;
    string designation = dgi.Cells[3].Text;

    conn.Open();
    SqlCommand comm = new SqlCommand("insert into [table] values (" + empid + ",'" + employeename + "','" + designation + "')", conn);
    comm.ExecuteNonQuery();
    conn.Close();        
}

推荐答案

可能 rbpApprove rbpReject 无法在同一时间检查...



查看下表和您的代码:



rbpApprove.Checked   rbpReject.Checked   结果  




你知道现在要查看if语句的内容吗?
Probably rbpApprove and rbpReject can not be checked in the same time...

Have a look at below table and your code:

rbpApprove.Checked  rbpReject.Checked  Result  
truetruetrue
truefalsefalse
falsetruetrue
falsefalsefalse


Do you know what to check in if statement, now?


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

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