注册 登录
编程论坛 ASP.NET技术论坛

datalist未知列赋值问题

狂砍程序 发布于 2008-08-25 19:10, 969 次点击
一个datalist中包含了一个DropDownList1和一个label1控件,要实现的功能是当DropDownList1选择项改变时,也就是DropDownList1_SelectedIndexChanged事件下怎么写代码来获取用户选择那个DropDownList1对应label1的值?
2 回复
#2
bygg2008-08-26 11:16
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DataList1.SelectedIndex != -1)
        {
            ((Label)DataList1.SelectedItem.FindControl("Label1")).Text = ((DropDownList)DataList1.SelectedItem.FindControl("DropDownList1")).SelectedItem.Value;
        }
    }
1