好吧,是这个样子的,前段时间做程序时候,发现前人留下来是程序组合,与界面搭配,是一个令人不爽的,首先在一个Repeater控件中有个RadioButtonList和DropDownList控件当更改RadioButtonList的选择项时候为DropDownList重新绑定数据protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
RadioButtonList rbl = sender as RadioButtonList; //找到控件本身
Repeater repS = rbl.Parent.Parent as Repeater; //drop的上一级的上一级控件就是Repeater控件
int n = ((RepeaterItem)rbl.Parent).ItemIndex; //获取当前选中行的索引
//查找其下班的dr控件
DropDownList drl = (DropDownList)(repS.Items[n].FindControl("ddlParent"));
if (rbl.SelectedValue == "1")
{
string sqlstring = "select i_id,s_name from tabuer where i_id=0";
drl.DataSource = new DB().getDs(sqlstring);
drl.DataTextField = "s_name";
drl.DataValueField = "i_id";
drl.DataBind();
drl.Visible = true;
}
else if (rbl.SelectedValue == "2")
{
string sqlstring = "s elect i_id,s_name from tabuer where i_id>0"
drl.DataSource = new DB().getDs(sqlstring);
drl.DataTextField = "s_name";
drl.DataValueField = "i_id";
drl.DataBind();
drl.Visible = true;
}
else
{
drl.Visible = false;
}
}
好的,程序就是这样完成的,至于如何生成这个RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
只能你自己想办法了,我的做法是在Repeater外添加一个新的RadioButtonList1控件,并未它生成RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e),随后删除这个外边的RadioButtonList1控件,把SelectedIndexChanged绑定到Repeater里边的RadioButtonList控件上就ok了。
沸腾建材招商网首发 转载请注明出处 http://www.1236.tv/