0

当我将下拉列表与两列连接时,我无法提取 sql 数据。我想结合姓氏(lName)+名字(fName)并提取这些名字的数据。这是我到目前为止所拥有的。

 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        DataSourceID="SqlDataSource3"  DataTextField="lName" DataValueField="lName" 
        AppendDataBoundItems="True" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
        <asp:ListItem Value="Select">Select</asp:ListItem>
    </asp:DropDownList>

  <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
        ConnectionString="<%$ ConnectionStrings:TestDBConnectionString1 %>" 
        SelectCommand="SELECT (lName + fName) AS zName FROM CoaTest"></asp:SqlDataSource>

然后我有一个包含所有 Databounds 的 formview,它的 sql 连接如下所示:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:TestDBConnectionString1 %>" 
        DeleteCommand="DELETE FROM [CoaTest] WHERE [Id] = @Id" 
        SelectCommand="SELECT Id, fName, lName, agency, title, gen, hired, AppS,
        course, Location, SessNum, SDate, EDate, Hours, SitUps, pushUps, rTime, 
        Grade FROM CoaTest WHERE (lName = @lName)"


        UpdateCommand="UPDATE [CoaTest] SET [fName] = @fName, [lName] = @lName, [agency] = @agency, [title] = @title, [gen] = @gen, [hired] = @hired, [AppS] = @Apps, [course] = @course, [Location] = @Location, [SDate] = @SDate, [EDate] = @EDate, [Hours] = @Hours WHERE [Id] = @Id">
        <DeleteParameters>
            <asp:Parameter Name="Id" Type="Int32" />
        </DeleteParameters>
        <SelectParameters> 
            <asp:ControlParameter ControlID="DropDownList1" Name="lName"  
                PropertyName="SelectedValue" Type="String" /> 

        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="fName" Type="String" />
            <asp:Parameter Name="lName" Type="String" />
            <asp:Parameter Name="Agency" Type="String" />
            <asp:Parameter Name="title" />
            <asp:Parameter Name="gen" />
            <asp:Parameter Name="hired" />
            <asp:Parameter Name="Apps" />
            <asp:Parameter Name="course" />
            <asp:Parameter Name="Location" />
            <asp:Parameter Name="SDate" />
            <asp:Parameter Name="EDate" />
            <asp:Parameter Name="Hours" />
            <asp:Parameter Name="Id" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>

如果我只是按姓氏 (lName) 拉取它,则此方法有效,但是当我尝试连接时,它不会从表单视图中拉取数据。先感谢您!!

4

2 回答 2

1

将下拉列表的选择命令更改为SELECT Id, (lName + fName) AS zName FROM CoaTest,将下拉列表的 DataValueField 值更改为Id并按 Id 而不是按名称选择数据到 FormView

于 2012-10-18T19:19:02.550 回答
0

我认为DataValueFieldDataTextField属性应该是这样的:

  • datavaluefield ="zname", 因为连接的别名被命名为 zname no lname

此外,您没有在数据源查询中投影或显示 lname 表列

于 2012-10-18T19:11:30.243 回答