将文本框绑定到 SQLDataSource 选择的字段 (VB.NET)

发布于 2024-10-16 06:15:28 字数 263 浏览 2 评论 0原文

我正在寻找将数据从 SqlDataSource 绑定到 Visual Studio 2008 中放置的文本框的最简单方法。

例如,我当前有 4 个文本框,其中包含地址、城市、州、邮政编码。我还在页面上有一个 SqlDataSource,用于获取记录的 ID 并根据 ID 选择这 4 个字段。

我如何能够快速将每个框绑定到所选的特定字段?我认为这真的很简单 - 但似乎并非如此。似乎答案是必须创建 GridView 或某种类型的控件。

温柔一点……我是个小笨蛋:)

I'm looking for the easiest way to bind data from a SqlDataSource to textboxes dropped in Visual Studio 2008.

For example, I have 4 textboxes currently that have Address, City, State, Zip. I also have a SqlDataSource on the page fetching the ID of the record and selecting those 4 fields based on ID.

How am I able to quickly bind each box to those particular fields selected? I would think this would be really straight forward - but seems it's not. Seems like the answer is funneled towards having to create a GridView or some type of control.

Be gentle...I'm a nub :)

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

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

发布评论

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

评论(1

靑春怀旧 2024-10-23 06:15:28

一般来说,您是正确的,如果您想使用数据绑定,则需要使用适当的控件。对于此示例,我建议使用 FormView - 它旨在显示单个数据库记录的结果并使用模板,这意味着您将完全控制输出。这篇文章可能是一个很好的起点:FormView 控件:一步一步< /a>.

要读取代码隐藏类中绑定到 FormView 的值,您需要为 FormView 的 DataBound 事件创建一个事件处理程序。在该事件处理程序中,您可以通过 FindControl 以编程方式引用控件,如下所示:

Dim myLabel As Label = CType(FormViewID.FindControl("id"), Label)

这里,id 将是您为其值的标签的 ID感兴趣。一旦您引用了 Label,您就可以使用 myLabel.Text 获取其值。

In general you are correct, if you want to use databinding you'll need to use an appropriate control. For this example I'd suggest using a FormView - it is designed to display the results from a single database record and uses templates, meaning you'll have complete control over the output. This article is probably a good place to start: FormView Control: Step by Step.

To read the values bound to the FormView in the code-behind class you would need to create an event handler for the FormView's DataBound event. In that event handler you would reference the controls programmatically via FindControl, like so:

Dim myLabel As Label = CType(FormViewID.FindControl("id"), Label)

Here, id would be the ID of the Label whose value you were interested in. Once you have a reference to the Label you can get its value using myLabel.Text.

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