我有一个 asp 按钮和四个从数据库动态填充的下拉列表。单击按钮时,应该将下拉列表中的选定值传递给 SQL 存储过程。相反,每个下拉列表中的第一个值被传递而不是选定的值。这是aspx页面上的代码:
<asp:DropDownList runat="server" ID="ddlCountry" AppendDataBoundItems="True">
</asp:DropDownList>
<asp:DropDownList runat="server" ID="ddlTypeStructure" AppendDataBoundItems="True">
</asp:DropDownList>
<asp:DropDownList runat="server" ID="ddlCategory" AppendDataBoundItems="True">
</asp:DropDownList>
<asp:DropDownList runat="server" ID="ddlSegment" AppendDataBoundItems="True">
</asp:DropDownList>
<asp:Button runat="server" ID="btnSearhProjects" Text="Go"
CausesValidation="False" onclick="btnSearhProjects_Click" UseSubmitBehavior="False" />
这是按钮背后的 C# 代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCountries();
BindCategories();
BindSegments();
BindStructures();
}
}
public void SearchProjects()
{
Project project = new Project();
string country = ddlCountry.SelectedItem.Text;
string category = ddlCategory.SelectedItem.Text;
string segment = ddlSegment.SelectedItem.Text;
string structure = ddlTypeStructure.SelectedItem.Text;
List<Project> projectList = project.GetProjects(country, category, segment, structure);
gvProjects.DataSource = projectList;
gvProjects.DataBind();
}
protected void btnSearhProjects_Click(object sender, EventArgs e)
{
SearchProjects();
}
这就是我填充每个下拉列表的方式:
public void BindCountries()
{
List<Country> countryList = new List<Country>();
Country country = new Country();
countryList = country.GetCountries();
ddlCountry.DataTextField = "CountryName";
ddlCountry.DataValueField = "CountryID";
ddlCountry.DataSource = countryList;
ddlCountry.DataBind();
}
我尝试过使用ddlCountry.SelectedValue.Text
并且ddlCountry.SelectedItem.Value
它们不起作用。任何帮助将不胜感激。谢谢你。