动态复选框问题! [英] Dynamic Checkboxes problem!

查看:65
本文介绍了动态复选框问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在webform(aspx)上动态创建复选框。在我创建

之后,当我检查任何复选框时,没有任何反应。这是我的代码

...

ArrayList LayerNameList1 = LayerNameList;


CheckBox [] checkBoxArray;

int BoxCount = 0;

HtmlTableRow newRow;

HtmlTableCell FieldCell;


System.Web。 UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();

checkBoxArray = new CheckBox [250];

foreach(LayerNameList1中的字符串项)

{

newRow = new HtmlTableRow();

FieldCell = new HtmlTableCell();

FieldCell.Style.Add(" font- family"," Arial");

FieldCell.Style.Add(" font-size"," small");

checkBoxArray [BoxCount] = new CheckBox();

checkBoxArray [BoxCount] .ID = Convert.ToString(BoxCount);

checkBoxArray [BoxCount] .Text = item;


checkBoxArray [BoxCount] .CheckedChanged + = new

System.EventHandler(checkBox_CheckedChanged);


FieldCell.Controls.Add(che ckBoxArray [BoxCount]);

newRow.Controls.Add(FieldCell);

ContainerTable.Controls.Add(newRow);

BoxCount ++;

}

this.placeHolder.Controls.Add(ContainerTable);

}


public void checkBox_CheckedChanged(object sender,System.EventArgs e)

{

CheckBox cb =(CheckBox)sender;


if( cb.Checked)

{testdel.Text =" 1" ;; }

其他

{testdel.Text =" 2";

}

}


有什么建议吗?


问候

Praveen


I create the checkboxes dynamically on my webform (aspx). after I create
them, when I check any of the checkboxes, nothing happens. Here is my code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen


推荐答案

嗨史蒂文,


我认为你应该设置AutoPostBack =" True"





" Steven"写道:
Hi Steven,

I think you should set AutoPostBack="True".

Jie

"Steven" wrote:
我在webform(aspx)上动态创建复选框。在我创建它们之后,当我检查任何复选框时,没有任何反应。这是我的代码


ArrayList LayerNameList1 = LayerNameList;

CheckBox [] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox [250];
foreach(LayerNameList1中的字符串项)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add(" font-family" ,Arial);
FieldCell.Style.Add(" font-size"," small");
checkBoxArray [BoxCount] = new CheckBox();
checkBoxArray [ BoxCount] .ID = Convert.ToString(BoxCount);
checkBoxArray [BoxCount] .Text = item;

checkBoxArray [BoxCount] .CheckedChanged + = new
System.EventHandler( checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray [BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow); < b r /> BoxCount ++;
}
this.placeHolder.Controls.Add(ContainerTable);
}
public void checkBox_CheckedChanged(object sender,System.EventArgs e)
{CheckBox cb =(CheckBox)发件人;

if(cb.Checked)
{testdel.Text =" 1" ;; }
其他
{testdel.Text =" 2" ;;
}


有什么建议吗?

问候
Praveen

I create the checkboxes dynamically on my webform (aspx). after I create
them, when I check any of the checkboxes, nothing happens. Here is my code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen



你好彭,


你能不能请告诉我,我应该在哪里设置AutoPostBack =" True"在代码下面的

。我试过checkBox_CheckedChanged函数。但似乎我很失心。


问候

史蒂文


彭杰 < Pe的***** @ discussions.microsoft.com>在留言中写道

新闻:2A ********************************** @ microsof t.com ...
Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in the
below code. I tried in checkBox_CheckedChanged function. But seems I''m
missing something.

Regards
Steven

"Peng Jie" <Pe*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
嗨史蒂文,

我认为你应该设置AutoPostBack =" True"

Jie

史蒂文写道:
Hi Steven,

I think you should set AutoPostBack="True".

Jie

"Steven" wrote:
我在webform(aspx)上动态创建复选框。在我创建它们之后,当我检查任何复选框时,没有任何反应。这是我的
代码


ArrayList LayerNameList1 = LayerNameList;

CheckBox [] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox [250];
foreach(LayerNameList1中的字符串项)
{/ / newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add(" font-family"," Arial");
FieldCell.Style.Add(" font-size"," small");
checkBoxArray [BoxCount] = new CheckBox();
checkBoxArray [BoxCount] .ID = Convert.ToString(BoxCount);
checkBoxArray [BoxCount] .Text = item;

checkBoxArray [BoxCount] .CheckedChanged + = new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray [BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add( newR ow);
BoxCount ++;
}
this.placeHolder.Controls.Add(ContainerTable);


public void checkBox_CheckedChanged(object sender,System .EventArgs e)
{CheckBox cb =(CheckBox)发件人;

if(cb.Checked)
{testdel.Text =" 1" ;; }
其他
{testdel.Text =" 2" ;;
}


有什么建议吗?

问候
Praveen

I create the checkboxes dynamically on my webform (aspx). after I create
them, when I check any of the checkboxes, nothing happens. Here is my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen



我的意思是你可以添加

checkBoxArray [BoxCount] .AutoPostBack = true;


进入你的foreach语句。

然后你可以解雇服务器端事件并调用CheckedChanged函数。


" Steven"写道:
What I mean is you can add

checkBoxArray[BoxCount].AutoPostBack = true;

into your foreach statement.
Then you can fire server side event and call CheckedChanged function.

"Steven" wrote:
你好彭,

你能告诉我,我应该在哪里设置AutoPostBack =" True"在下面的代码中。我试过checkBox_CheckedChanged函数。但似乎我错过了一些东西。

问候
史蒂文

彭杰 < Pe的***** @ discussions.microsoft.com>在消息中写道
新闻:2A ********************************** @ microsof t.com。 ..
Hello Peng,

Could you please tell me, where should I set AutoPostBack="True" in the
below code. I tried in checkBox_CheckedChanged function. But seems I''m
missing something.

Regards
Steven

"Peng Jie" <Pe*****@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
嗨史蒂文,

我认为你应该设置AutoPostBack =" True"



"史蒂芬"写道:
Hi Steven,

I think you should set AutoPostBack="True".

Jie

"Steven" wrote:
我在webform(aspx)上动态创建复选框。在我创建它们之后,当我检查任何复选框时,没有任何反应。这是我的
代码


ArrayList LayerNameList1 = LayerNameList;

CheckBox [] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox [250];
foreach(LayerNameList1中的字符串项)
{/ / newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add(" font-family"," Arial");
FieldCell.Style.Add(" font-size"," small");
checkBoxArray [BoxCount] = new CheckBox();
checkBoxArray [BoxCount] .ID = Convert.ToString(BoxCount);
checkBoxArray [BoxCount] .Text = item;

checkBoxArray [BoxCount] .CheckedChanged + = new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray [BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add( newR ow);
BoxCount ++;
}
this.placeHolder.Controls.Add(ContainerTable);


public void checkBox_CheckedChanged(object sender,System .EventArgs e)
{CheckBox cb =(CheckBox)发件人;

if(cb.Checked)
{testdel.Text =" 1" ;; }
其他
{testdel.Text =" 2" ;;
}


有什么建议吗?

问候
Praveen

I create the checkboxes dynamically on my webform (aspx). after I create
them, when I check any of the checkboxes, nothing happens. Here is my
code
...

ArrayList LayerNameList1 = LayerNameList;

CheckBox[] checkBoxArray;
int BoxCount = 0;
HtmlTableRow newRow;
HtmlTableCell FieldCell;

System.Web.UI.HtmlControls.HtmlTable ContainerTable = new HtmlTable();
checkBoxArray = new CheckBox[250];
foreach(string item in LayerNameList1)
{
newRow = new HtmlTableRow();
FieldCell = new HtmlTableCell();
FieldCell.Style.Add("font-family", "Arial");
FieldCell.Style.Add("font-size", "smaller");
checkBoxArray[BoxCount] = new CheckBox();
checkBoxArray[BoxCount].ID = Convert.ToString(BoxCount);
checkBoxArray[BoxCount].Text = item;

checkBoxArray[BoxCount].CheckedChanged += new
System.EventHandler(checkBox_CheckedChanged);

FieldCell.Controls.Add(checkBoxArray[BoxCount]);
newRow.Controls.Add(FieldCell);
ContainerTable.Controls.Add(newRow);
BoxCount++;
}
this.placeHolder.Controls.Add(ContainerTable);
}

public void checkBox_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox cb = (CheckBox) sender;

if (cb.Checked)
{ testdel.Text = "1"; }
else
{ testdel.Text = "2";
}
}

Any suggestions?

Regards
Praveen




这篇关于动态复选框问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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