从vb.net代码更新ASP SQLDataSource更新参数 [英] Update ASP SQLDataSource update parameter from vb.net code
问题描述
这就是我想要做的:
我在Formview中有一个DropDownList,如果网站用户需要添加新值,则可以单击一个按钮.该按钮隐藏DropDownList并显示一个文本框.这一切都很好. TextBox和DropDownList不绑定.如何从TextBox或DropDownlist顶部的ASP.net更新参数传递值?
ASP:
Here is what I am trying to do:
I have a DropDownList in a Formview that if a website user needs to add a new value, they click a button. The button hide the DropDownList and shows a text box. This all works fine. The TextBox and DropDownList are not bind. How to I pass the value from the TextBox or the DropDownlist top my ASP.net update parameter?
ASP:
UpdateCommand="UPDATE [zEdits] SET [Supervisor] = @Supervisor WHERE [ID] = @ID">
<asp:Parameter Name="Supervisor" Type="String" />
<%--other parameters removed--%>
<asp:Label ID="lblSupervisor" runat="server" Text="Supervisor:" class="styleDBLabeltag" />
<asp:Button ID="AddSupervisorItem" runat="server" OnClick="btnAddSupervisor_Click" />
<asp:Button ID="SupervisorItemAdded" runat="server" OnClick="btnSupervisorAdded_Click" Visible="false" />
<asp:DropDownList ID="DropDownListSupervisor" runat="server" AutoPostBack="true"
DataSourceID="SupervisorDDLSelect" DataValueField="Name" >
<asp:SqlDataSource ID="SupervisorDDLSelect" runat="server"
ConnectionString="<%$ ConnectionStrings:PKLConnectionString %>"
SelectCommand="SELECT [LastName] + ', ' + [FirstName] as Name FROM [tblPersonnel] ORDER BY [Name]">
vb.net代码:
vb.net code:
Protected Sub btnAddSupervisor_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txtSupervisorValue As TextBox = Me.FormView1.FindControl("SupervisorLabel1")
Dim ddlSupervisor As DropDownList = Me.FormView1.FindControl("DropDownListSupervisor")
'Dim lstSupervisorItem As ListItem
'Dim SupervisorStringToFind As String
txtSupervisorValue.Visible = True
ddlSupervisor.Visible = True
Me.FormView1.FindControl("SupervisorItemAdded").Visible = True
Me.FormView1.FindControl("AddSupervisorItem").Visible = False
End Sub
Protected Sub btnSupervisorAdded_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txtSupervisorValue As TextBox = Me.FormView1.FindControl("SupervisorLabel1")
Dim ddlSupervisor As DropDownList = Me.FormView1.FindControl("DropDownListSupervisor")
'Dim lstSupervisorItem As ListItem
Dim SupervisorStringToFind As String
SupervisorStringToFind = txtSupervisorValue.Text
ddlSupervisor.Items.Insert(0, SupervisorStringToFind)
ddlSupervisor.SelectedValue = SupervisorStringToFind
End Sub
注意:如果尝试使用SELECTEDVALUE属性,则无法编辑FormView按钮不起作用.
NOTE: If I try use the SELECTEDVALUE property, I can not edit FormView button doesn''t work.
推荐答案
ConnectionStrings:PKLConnectionString%>" =" 选择[姓氏] +','+ [名字]作为名称,由[tblPersonnel]排序[名称]" >
ConnectionStrings:PKLConnectionString %>" SelectCommand="SELECT [LastName] + ', ' + [FirstName] as Name FROM [tblPersonnel] ORDER BY [Name]">
vb.net代码:
vb.net code:
Protected Sub btnAddSupervisor_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txtSupervisorValue As TextBox = Me.FormView1.FindControl("SupervisorLabel1")
Dim ddlSupervisor As DropDownList = Me.FormView1.FindControl("DropDownListSupervisor")
'Dim lstSupervisorItem As ListItem
'Dim SupervisorStringToFind As String
txtSupervisorValue.Visible = True
ddlSupervisor.Visible = True
Me.FormView1.FindControl("SupervisorItemAdded").Visible = True
Me.FormView1.FindControl("AddSupervisorItem").Visible = False
End Sub
Protected Sub btnSupervisorAdded_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txtSupervisorValue As TextBox = Me.FormView1.FindControl("SupervisorLabel1")
Dim ddlSupervisor As DropDownList = Me.FormView1.FindControl("DropDownListSupervisor")
'Dim lstSupervisorItem As ListItem
Dim SupervisorStringToFind As String
SupervisorStringToFind = txtSupervisorValue.Text
ddlSupervisor.Items.Insert(0, SupervisorStringToFind)
ddlSupervisor.SelectedValue = SupervisorStringToFind
End Sub
注意:如果尝试使用SELECTEDVALUE属性,则无法编辑FormView按钮不起作用.
NOTE: If I try use the SELECTEDVALUE property, I can not edit FormView button doesn''t work.
这篇关于从vb.net代码更新ASP SQLDataSource更新参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!