这段代码会获取找到的控件的值吗? ASP.NET 语法

发布于 2024-08-22 04:28:12 字数 154 浏览 4 评论 0原文

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

它应该找到 AreasExpertise1 并创建一个参数,但这是否也能获取选定的值?

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

It should find AreasExpertise1 and make a parameter, but does that get the selectedvalue too?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我鬧 2024-08-29 04:28:12

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

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

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

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文