从vb.net代码更新ASP SQLDataSource更新参数 [英] Update ASP SQLDataSource update parameter from vb.net code

查看:74
本文介绍了从vb.net代码更新ASP SQLDataSource更新参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要做的:

我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆