如何访问在Gridview中显示为复选框的布尔值 [英] How To Access The Value Of A Boolean Which Is Displayed Within A Gridview As A Checkbox

查看:221
本文介绍了如何访问在Gridview中显示为复选框的布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何访问在GridView中显示为复选框的布尔值吗?标准的Grid视图会将位类型(即布尔值)数据类型呈现到ASP:CheckBoxField中,但是我如何才能访问基础数据的值(是/否).

Does anyone know how to access the value of a Boolean which is displayed within a gridview as a checkbox?? The standard Grid view will render a bit type (i.e. Boolean) datatype into an ASP:CheckBoxField, but how can i access the value of the underlying data, either true/false.

推荐答案

您好,
我已经在Windows应用程序Gridview的click事件中完成了类似的操作,我想访问网格的选定行的第9个单元格值(即复选框),请尝试执行此操作并使您的逻辑:)

Hi,
I have done the similar thing in windows app Gridview''s click event,i want to access grid''s selected row''s 9th cell value which is a check box,try this and make your logic :)

string valuechk = dataGridView1.CurrentRow.Cells[9].Value.ToString ();
// int value = int.Parse(valuechk);
 bool chkvalue = Convert.ToBoolean(valuechk);

 //if (dataGridView1.CurrentRow.Cells[8].Value == "0")
 if(chkvalue ==false)
      assignchk.Checked = false;//assignchk is a check box on form
  else
      assignchk.Checked = true;




如果可以满足您的需求,请尝试此操作,并且可以帮助您...

在您的客户代码中:
Hi,

Try this if could fit to your needs, and could help...

In your client code:
<asp:TemplateField HeaderText="Delete">
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>



在后面的代码中(示例):



In your Code behind (example):

protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < grdDeleteTransaction.Rows.Count; i++)
        {
            var row = grdDeleteTransaction.Rows[i];
            var isTag = row.FindControl("CheckBox1");
            CheckBox checkbox = (CheckBox)isTag;
            if (checkbox.Checked)
            {
                // Do something here...               
            }
            else
            {
               // Do something here...  
            }
        }
        //.. 
    }




请记住,如果有帮助,请将其标记为答案;如果没有帮助,则将其取消标记.


问候,

代数




Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Regards,

Algem


这篇关于如何访问在Gridview中显示为复选框的布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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