找DATALIST中的控件

来源:百度知道 编辑:UC知道 时间:2024/05/29 15:46:34
我想实现判断RadioButton 是否选中,然后更新,可是rb的返回值为空
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";
}
else
{
top = "0";
}

string Site_name = ((TextBox)e.Item.FindControl("TextBox1")).Text;
string Content = ((TextBox)e.Item.FindControl("TextBox2")).Text;
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();

SqlCommand cmd = new SqlCommand("Update Case_Management Set Site_name='" + Site_name + &quo

全写到ItemCommand中不就行了

foreach (DataListItem item in DataList1.Items)
{
chk = item.FindControl("CheckBox1") as CheckBox;
if (chk != null && chk.Checked)
{
Label lbOne = item.FindControl("lbName") as Label;
//依次寻找你需要的值
if (lbOne != null)
{
//证明找到了
}
}
}

DataList的ispostback属性设为true就可以了。