datagrid多个checkbox 高手进!急!! datagrid中我用模板列绑定了多个checkbox,当我选中其中某一个是如何知道我选中的是那一行的那个,我要把更改后的值自动更新到数据库怎么做,一直无法获取点的是那行的checkbox,一个晚上没有解决,急,高手帮帮忙!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int startIndex = 0; CheckBox cbProcessed = new CheckBox(); foreach(GridViewRow rows in AllAppointmentsGridView.Rows) { cbProcessed = (CheckBox)rows.FindControl("newcbProcessed"); if(cbProcessed.Checked) { startIndex = rows.DataItemIndex DataKey keyValue = AllAppointmentsGridView.DataKeys[startIndex]; string clientId = keyValue[0].ToString(); Int32 hubId = Convert.ToInt32(keyValue[1]); Int32 appointmentId = Convert.ToInt32(keyValue[2]); Int32 doctorTypeID = Convert.ToInt32(keyValue[3]); cswAppointments.BFInsertDataToCalendar(hubId, appointmentId, this.UserID, this.viewTime, this.insertTime, doctorTypeID, clientId);//存储过程 } } http://www.cnblogs.com/ilovejolly/archive/2006/10/24/538120.html foreach (DataGrid gvr in DataGrid1.Rows) { CheckBox cb = (CheckBox)gr.FindControl("CheckBox1"); if (cb.Checked)这几句话是重点按行遍历DataGrid1取出每一行的checkbox判断是否被选中 1楼的正确!支持lxmfll2000(lxm) 多谢大家帮忙,我的问题还没有解决,我就没有放任何按钮,不能执行按钮事件,我的意思是点一下datagrid中的checkbox,数据库中自动更新,我的代码如下:private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.Item) { CheckBox chk = (CheckBox)e.Item.FindControl("cb"); chk.CheckedChanged +=new EventHandler(chk_CheckedChanged); } }private void chk_CheckedChanged(object sender, System.EventArgs e) { //就是不知道当点中一个CheckBox时这个事件中怎么获得是点中的那一个。 }一个很令我头痛的问题,请各位高手帮帮忙。 我借这个问题来推销一下asp.net控件的“简易扩展”的功效:public class myCheckBox: CheckBox{ [DefaultValue(null)] public string datakey { get{ return (string)ViewState["datakey"]; } set{ ViewState["datakey"]=value; } }}然后你的工程编译之后,你的控件工具箱里就有了这个自定义的控件myCheckBox了。之后在你的datagrid的模板列里不要使用CheckBox,使用myCheckBox,并且为其datakey绑定某个数据(例如绑定当前数据行的key值)。asp.net是个自顶向下把组件式开发技术设计得很周全的操作系统,绑定表达式、组件的继承层次、ItTemplate等扩展技术都是相辅相成的。最后,在chk_CheckedChanged中使用 ((myCheckBox)object).datakey就能取出当初绑定的数据了。asp.net控件是很简单的,多多学习控件知识,从原有的控件上扩展功能。 如何拉伸div的背景图片 datagrid内部控件的引用? 我想知道微软的网站那些帮助是怎么做出来的,有源代码的进 请教一个郁闷的问题oxmlHTTP 怎样可以让自定义的类支持数组表示???? 如何将一个dataset分到两个datagrid绑定 一个小小的问题 登录web应用系统的问题! 怎么在flash上面放一个button呢? 用asp.net,大家用什么开发工具? 用<input type="file"..>上传文件时,一有事件触发文本框中的值就没了,怎么能存住值? ★★★GridView控件问题!!!!在线等到死!!!!!★★★分就剩这么多了..对不住了..
CheckBox cbProcessed = new CheckBox();
foreach(GridViewRow rows in AllAppointmentsGridView.Rows)
{
cbProcessed = (CheckBox)rows.FindControl("newcbProcessed");
if(cbProcessed.Checked)
{
startIndex = rows.DataItemIndex
DataKey keyValue = AllAppointmentsGridView.DataKeys[startIndex];
string clientId = keyValue[0].ToString();
Int32 hubId = Convert.ToInt32(keyValue[1]);
Int32 appointmentId = Convert.ToInt32(keyValue[2]);
Int32 doctorTypeID = Convert.ToInt32(keyValue[3]);
cswAppointments.BFInsertDataToCalendar(hubId, appointmentId, this.UserID, this.viewTime, this.insertTime, doctorTypeID, clientId);//存储过程 } }
{
CheckBox cb = (CheckBox)gr.FindControl("CheckBox1");
if (cb.Checked)
这几句话是重点
按行遍历DataGrid1
取出每一行的checkbox
判断是否被选中
支持lxmfll2000(lxm)
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item)
{
CheckBox chk = (CheckBox)e.Item.FindControl("cb");
chk.CheckedChanged +=new EventHandler(chk_CheckedChanged);
}
}private void chk_CheckedChanged(object sender, System.EventArgs e)
{
//就是不知道当点中一个CheckBox时这个事件中怎么获得是点中的那一个。
}一个很令我头痛的问题,请各位高手帮帮忙。
{
[DefaultValue(null)]
public string datakey
{
get{ return (string)ViewState["datakey"]; }
set{ ViewState["datakey"]=value; }
}
}然后你的工程编译之后,你的控件工具箱里就有了这个自定义的控件myCheckBox了。之后在你的datagrid的模板列里不要使用CheckBox,使用myCheckBox,并且为其datakey绑定某个数据(例如绑定当前数据行的key值)。asp.net是个自顶向下把组件式开发技术设计得很周全的操作系统,绑定表达式、组件的继承层次、ItTemplate等扩展技术都是相辅相成的。最后,在chk_CheckedChanged中使用
((myCheckBox)object).datakey
就能取出当初绑定的数据了。asp.net控件是很简单的,多多学习控件知识,从原有的控件上扩展功能。