如何将TextBox绑定到SqlDataSource [英] How to Bind TextBox to SqlDataSource
问题描述
亲爱的朋友们,
我正在制作WebPage,在SqlDataSource中存储客户端的详细信息。我使用TextBox作为名称,地址,联系号码。我想要知道如何将TextBox绑定到SqlDataSource吗?
谢谢你,
http://www.mikesdotnetting.com/Article/64/Bind-Data-From -a-SqlDataSource-to-a-label [ ^ ]
创建服务器端文本框控件
< asp:textbox < span class =code-attribute> id = txtName runat = server xmlns:asp = #unknown > < / asp:textbox >
创建数据源
< asp:SqlDataSource ID = SqlDataSource1 runat = 服务器
<跨度class =code-attribute> ConnectionString = < ;%
ConnectionStrings:MyConnectionString %>
SelectCommand = SELECT * FROM [PersonalDetails] >
< / asp:SqlDataSource >
写在页面加载事件的代码隐藏页面上写下面的代码
< pre lang =vb> 受保护的 Sub Page_Load( ByVal sender 正如 对象, ByVal e As System.EventArgs)句柄 我。加载
Dim dv As DataView = DirectCast (SqlDataSource1。选择(DataSourceSelectArguments.Empty),DataView)
对于 每个 drv 作为 DataRowView 在 dv
txtName.Text = drv( 名称)。ToString()
下一步
结束 Sub
Dear Friends,
I am making WebPage which store detail of Client in SqlDataSource.I am using TextBox for Name,Address,Contact No.. I want to know how we can bind TextBox to SqlDataSource?.
Thankyou,
http://www.mikesdotnetting.com/Article/64/Bind-Data-From-a-SqlDataSource-to-a-Label[^]
create a server side text Box control
<asp:textbox id="txtName" runat="server" xmlns:asp="#unknown"></asp:textbox>
create a datasource
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%
ConnectionStrings:MyConnectionString %>" SelectCommand="SELECT * FROM [PersonalDetails]" > </asp:SqlDataSource>
write in codebehind page on Page load event write the below code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim dv As DataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView) For Each drv As DataRowView In dv txtName.Text = drv("Name").ToString() Next End Sub
这篇关于如何将TextBox绑定到SqlDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!