找不到DATALIST中的控件

来源:百度知道 编辑:UC知道 时间:2024/06/22 15:48:50
我找不到DATALIST中的RadioButton,
//for (int i = 0; i < DataList1.Items.Count; i++)
//{
// RadioButton rb = (RadioButton)DataList1.Items[i].FindControl("rbTop");

// string top;
// if (rb.Checked)
// {
// top = "1";
// }
// else
// {
// top = "0";
// }
rb的返回值是null,怎回事;帮帮我吧
我是新手(新手中的新手),说的清楚一点,最好有代码!!
我想在datalist中看RadioButton 是否被选中;可能是我的逻辑错了,只要能实现效果
protected void DataList1_Update(object source, DataListCommandEventArgs e)
{
for (int i = 0; i < DataList1.Items.Count; i++)
{
RadioButton rb = new RadioButton();
rb = (RadioButton)DataList1.Items[i].FindControl("rbTop");
string top;
if (rb.Checked)
top = "1&quo

好吧 分拿来吧.累死俺了...几百年没碰C#了..

你弄错事件了,要在itermCommand里边写
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
RadioButton rb = (RadioButton)DataList1.Items[i].FindControl("rbTop");
string top;
if (rb.Checked)
{
top = "1";
}
else
{
top = "0";
}

}
这样才能找到时哪一行里边的redio

int count = this.DataList1.Items.Count;
for (int i = 0; i < count; i++)
{
string top;
RadioButton rb = (RadioButton)this.DataList1.Items[i].FindControl("rbTop");
if (rb != null&&rb.Checked)
{
top = "1";
break;
}
if (rb != null&&rb.Checked==false)