如何取得在DataGrid的Header中的控件的值?

cyanman 2003-07-30 09:03:28
我在Header中放了一个CheckBox控件,但怎么也取不到它的值,我用
if(((CheckBox)DataGrid1.FindControl("cbxAll")).Checked)
{
。。。
}
提示未将对象应用到实例。
请问各位高手,如何解决?
...全文
116 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cyanman 2003-07-31
  • 打赏
  • 举报
回复
如果今天下午不下雨的话,俺就去公园睡觉。
如果今天晚上问题还没有解决的话,俺就准备买单。
SimonSnow 2003-07-30
  • 打赏
  • 举报
回复
检查一下你的CheckBox的Name属性。(AssembleName?)
因为FindControl的参数是控件的name而不是控件变量的名字
好运 2003-07-30
  • 打赏
  • 举报
回复
good
雪狼1234567 2003-07-30
  • 打赏
  • 举报
回复
没有实例化,参考如下的代码:
// code assumes you have a DataSet named myDataSet, a table named "EastCoastSales" and a DataGrid myDataGrid

//STEP 1: Create a DataTable style object and set properties if required.

DataGridTableStyle ts1 = new DataGridTableStyle();



//specify the table from dataset (required step)

ts1.MappingName = "EastCoastSales";



// Set other properties (optional step)

ts1.AlternatingBackColor = Color.LightBlue;



//STEP 2: Create a string column and add it to the tablestyle

DataGridColumnStyle TextCol = new DataGridTextBoxColumn();

TextCol.MappingName = "custName"; //from dataset table

TextCol.HeaderText = "Customer Name";

TextCol.Width = 250;

ts1.GridColumnStyles.Add(TextCol);



//STEP 3: Create an int column style and add it to the tablestyle

//this requires setting the format for the column through its property descriptor

PropertyDescriptorCollection pdc = this.BindingContext

[myDataSet, "EastCoastSales"].GetItemProperties();



//now created a formated column using the pdc

DataGridDigitsTextBoxColumn csIDInt =

new DataGridDigitsTextBoxColumn(pdc["CustID"], "i", true);

csIDInt.MappingName = "CustID";

csIDInt.HeaderText = "CustID";

csIDInt.Width = 100;

ts1.GridColumnStyles.Add(csIDInt);



//STEP 4: Add the checkbox

DataGridColumnStyle boolCol = new DataGridBoolColumn();

boolCol.MappingName = "Current";

boolCol.HeaderText = "Info Current";



//uncomment this line to get a two-state checkbox

//((DataGridBoolColumn)boolCol).AllowNull = false;



boolCol.Width = 150;

ts1.GridColumnStyles.Add(boolCol);



//STEP 5: Add the tablestyle to your datagrid's tablestlye collection

myDataGrid.TableStyles.Add(ts1);

superxmz 2003-07-30
  • 打赏
  • 举报
回复
你用的是客户端的checkbox吗?
cyanman 2003-07-30
  • 打赏
  • 举报
回复
我忘了说一件很重要的事(我先掌自已一个大嘴巴),我这是在WEB页中的DataGrid,不能使用象DataGridColumnStyle这样的类。

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧