如何将Datagridview复选框的列值转换为复选框? [英] How to get Datagridview Checkbox Colomn Value to a Checkbox?

查看:86
本文介绍了如何将Datagridview复选框的列值转换为复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何将datagridview复选框的列值提取到复选框吗?
例子:

Can somebody could tell me how to Extract datagridview Checkbox Colomn Value to a Check box?
example :

txthubname.Text = hubGridView.SelectedRow.Cells[2].Text;
txtdescription.Text = hubGridView.SelectedRow.Cells[3].Text;
bbtcheckbox.checked = (CheckBox)hubGridView.SelectedRow.Cells[4].Controls(0);


我想将那个checkboxGridview单元格值设置为bbtcheckbox?


i want to get that checkboxGridview Cell value to the bbtcheckbox? so can someone help me on this?

推荐答案

您可以使用FindControl方法.

试试类似的东西:
You can use FindControl method.

Try something like:
foreach (GridViewRow item in myGrid.Rows) 
{    
    CheckBox myCheckBox = (CheckBox)item.FindControl("myCheckBox");
    if (myCheckBox.Checked)    
    {     
        Label myLabel = (Label)item.FindControl("myLabel");
        string text = myLabel.Text;
        //use the text now           
    }             
} 


使用行数据绑定事件...

use row data bound event...

void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
  {
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
     CheckBox chk=(CheckBox)e.Row.cells[0].FindControl("chkMyCheckBox");
     if(chk != null)
     {
      if(e.Row.Cells[5].Text == "1") //check for status column
      chk.Checked = true;
     }
    }
  }



您可以在if条件中使用列而不是1.



you can use your column instead of 1 in if condition..


这篇关于如何将Datagridview复选框的列值转换为复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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