• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

访问在Gridview显示为复选框的布尔值

用户头像
it1352
帮助1

问题说明

有人知道如何访问在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.

正确答案

#1
您好,
我已经在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   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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcakhjk
系列文章
更多 icon
同类精品
更多 icon
继续加载