【问题标题】:Firing Datasources触发数据源
【发布时间】:2013-12-06 08:30:00
【问题描述】:

在我的表单上,我有一个包含员工姓名的下拉列表。我有一个绑定到下拉列表的数据源,因此当您打开表单时,用户会自动填写。在下拉列表上方我有 onClick 时的链接按钮(AZ),它们应该通过另一个数据源过滤一个按字母过滤并在下拉列表中输出的 sp。我知道 onClick 正在触发,但下拉列表没有被新数据填充。任何建议或帮助将不胜感激。 每个链接按钮 x26 的代码

<asp:LinkButton ID="LinkA" runat="server" CausesValidation="False" 
          Font-Size="Small" ForeColor="#0B446A" Text="A" Font-Underline="True" 
          OnClick="link_click" Font-Bold="True"></asp:LinkButton>

后面的代码

Protected Sub link_click(ByVal sender As Object, _
             ByVal e As System.EventArgs) 
    ColorReset()
    Dim link As LinkButton = sender
    Session("filterletter") = link.Text
    Session("linkclick") = "yes"
End Sub

数据源1

<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:RequestSystemConnectionString %>" 
                    SelectCommand="userinfo" SelectCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:SessionParameter Name="user" SessionField="user" Type="Int32" />
                    </SelectParameters>

                </asp:SqlDataSource>

数据源2

    ConnectionString="<%$ ConnectionStrings:RequestSystemConnectionString %>" SelectCommand="current_employees_byletter" 
                SelectCommandType="StoredProcedure" >
                    <SelectParameters>
                        <asp:SessionParameter Name="letter" SessionField="filterletter" Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>

Datasource1 后面的代码

If Page.IsPostBack = False Then
        Dim dv As New DataView
        dv = SqlDataSource1.Select(DataSourceSelectArguments.Empty) 

DropDownList1.SelectedValue = Trim(dv.Item(0).Item("userid").ToString) TextBox1.Text = DropDownList1.SelectedValue.ToString

【问题讨论】:

  • 听起来您可能需要在代码后面添加一行...类似于下拉列表点绑定以刷新下拉列表控件和数据源之间的绑定。
  • 请显示 DropDownList 的标记,以及将数据绑定到它的代码。
  • @nocturns2 我不确定如何将下拉列表准确绑定到新数据源。 Datasource1 数据绑定到下拉列表并反映正在选择的用户。我的问题是如何将 datasource2 绑定到下拉列表,因此当单击链接按钮时,相应的名称将只是下拉列表中的选项。
  • @jadarnel27 上面的额外信息可能会更好地解释。
  • 谢谢,这确实有帮助。你还能编辑你的问题并添加 DropDownList 标记吗?以及数据源的标记?

标签: asp.net vb.net drop-down-menu datasource


【解决方案1】:

经过数小时的尝试,我想出了如何将下拉列表连接到不同的数据源。感谢所有观看和评论的人。最终,我在 preRenderComplete 中为每个数据源创建了数据视图。

【讨论】:

    【解决方案2】:

    您应该能够在链接点击事件中更改 DropDownList 的数据源目标:

    Protected Sub link_click(ByVal sender As Object, ByVal e As System.EventArgs) 
        ColorReset()
        Dim link As LinkButton = sender
        Session("filterletter") = link.Text
        Session("linkclick") = "yes"
        ' Update the "DataSourceID" field to be the ID of your other datasource
        DropDownList1.DataSourceID = dsEmpByLetter
    End Sub
    

    注意:如果您还没有这样做,您应该将 DropDownList 的“DataTextField”和“DataValuefield”属性设置为数据源中相应的列名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      相关资源
      最近更新 更多