当我执行查询字符串参数时,下拉列表中的值不会传递到下一页

时间:2015-02-20 18:33:46

标签: asp.net

我尝试使用下拉列表的DataTextField属性来完成指向要导航到的页面的链接。这是代码:

page1.aspx这个

<table>
    <tr>
        <td>Search by last name: <asp:TextBox ID="searchTB" runat="server"/><br />
        Search by first name: <asp:TextBox ID="FNameTB" runat="server"/><br />
        </td>
        <td style="padding-left: 10px;">
            Search by Organization: <asp:DropDownList ID="OrgDDL" runat="server" 
                DataSourceID="AccessDataSource2" DataTextField="SectionName" 
                DataValueField="ID">
            </asp:DropDownList>
            <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
                DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [ORG_SECTIONS]">
            </asp:AccessDataSource>
        </td>
    </tr>
    <tr>
        <td style="text-align: center;"><asp:Button ID="Button1" runat="server" Text="Search" OnClick="Search" /></td>
        <td style="padding-left: 10px; text-align: center;"><asp:Button ID="SearchbyOrgBtn" runat="server" Text="Search" OnClick="SearchByOrg" /></td>
    </tr>
</table>

代码背后:

protected void Search(object sender, EventArgs e)
{
    //TextBox LastName = (TextBox)this.FindControl("searchTB");
    Response.Redirect("OrgsByName.aspx?LASTNAME=" + searchTB.Text);
}
protected void SearchByOrg(object sender, EventArgs e)
{
    //TextBox LastName = (TextBox)this.FindControl("searchTB");
    Response.Redirect("NamesByOrg.aspx?SectionName=" + OrgDDL.DataTextField);
}

NamesByOrg.aspx:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
    DataFile="~/App_Data/webvideos.mdb" 
    SelectCommand="SELECT ORGANIZATIONS.ORG_NAME, ORG_SECTIONS.SectionName, ATTORNEYS.NAME, ATTORNEYS.LASTNAME, ATTORNEYS.EMAIL, ATTORNEYS.TEL
         FROM (ORGANIZATIONS INNER JOIN (Org_Sec_Atty INNER JOIN ATTORNEYS ON Org_Sec_Atty.Atty_ID = ATTORNEYS.ATTY_ID) ON ORGANIZATIONS.ID = Org_Sec_Atty.OrgID) INNER JOIN ORG_SECTIONS ON Org_Sec_Atty.SecID = ORG_SECTIONS.ID
         WHERE ORG_SECTIONS.SectionName LIKE @SectionName;">
    <SelectParameters>
        <asp:QueryStringParameter Name="SectionName" QueryStringField="SectionName" />
    </SelectParameters>
</asp:AccessDataSource>

我在DDL中选择的值并不重要,它总是尝试导航到&#34; NamesByOrg.aspx?SectionName = SectionName&#34;。当我把它作为一个文本框时,它运行正常,但我想将它作为DDL保留,原因很明显,哈哈。

1 个答案:

答案 0 :(得分:0)

DataTextField的值在您提供的.aspx中定义,恰好是"SectionName"

您正在寻找的内容类似于SelectedValueSelectedItem,它会返回您在下拉菜单中选择的内容。