如何将Datagridview复选框的列值转换为复选框?

编程入门 行业动态 更新时间:2024-10-27 09:36:48
本文介绍了如何将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复选框的列值转换为复选框?

本文发布于:2023-11-07 09:02:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566048.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   转换为   如何将   Datagridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!