开发者

Will this code get the value of the found control? asp.net syntax

开发者 https://www.devze.com 2022-12-20 18:03 出处:网络
x.Parameters.AddWithValue(\"@areasexpertise1\", FindControl(\"AreasExpertise1\")) It should find AreasExpertise1 and make a paramete开发者_JS百科r, but does that get the selectedvalue too?The code y
x.Parameters.AddWithValue("@areasexpertise1", FindControl("AreasExpertise1"))

It should find AreasExpertise1 and make a paramete开发者_JS百科r, but does that get the selectedvalue too?


The code you posted will find the control and will return it as a Control object.

You need to cast it to whatever control it is (DropDownList or RadioButtonList, or whatever it is you are using), and then call the SelectedValue property on it in order to do so:

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

精彩评论

暂无评论...
验证码 换一张
取 消