这段代码会获得找到的控件的值吗? asp.net语法

时间:2010-02-18 08:27:13

标签: asp.net vb.net findcontrol

x.Parameters.AddWithValue("@areasexpertise1", FindControl("AreasExpertise1"))

它应该找到AreasExpertise1并创建一个参数,但这样做也会得到selectedvalue吗?

1 个答案:

答案 0 :(得分:1)

您发布的代码将找到该控件,并将其作为Control对象返回。

您需要将其强制转换为任何控件(DropDownList或RadioButtonList,或者您正在使用的任何控件),然后在其上调用SelectedValue属性以执行此操作:

var ctrl = FindControl("AreasExpertise1") as DropDownList;
if (ctrl != null)
  x.Parameters.AddWithValue("@areasexpertise1", ctrl.SelectedValue)