aspproblems正在获取下线列表
本文关键字:列表 获取 aspproblems | 更新日期: 2023-09-27 18:01:04
我正在使用一个代码隐藏函数来动态绑定我的下拉列表,当用户更改下拉列表并提交购买时,selectedvalue始终为空。
两种ddl我都试过了。SelectedItem.ToString((;和ddl。SelectedValue.ToString((;但都不起作用。同样,对于下面的这两个代码背后的函数,我似乎不能使用void方法来代替需要返回值和参数的函数,是否可以使用没有参数的void方法?欢迎提出任何建议。
谢谢。
<%# FormattedSize((string)Eval("Size")) %>
<%# FormattedGetSize((string)Eval("Size")) %>
内联:
<asp:DropDownList ID="DropDownList1" runat="server" OnDataBinding='<%# FormattedSize((string)Eval("Size")) %>'></asp:DropDownList>
<a href='AddToCart.aspx?CategoryId=<%# Eval("CategoryId") %>&&ProductId=<%# Eval("ProductId" ) %>&&Size=<%# FormattedGetSize((string)Eval("Size")) %>' style="border: 0 none white;">
代码隐藏:
protected string FormattedSize(string size)
{
if (size.Contains("s"))
{
DropDownList ddl = (DropDownList)FormView_Product.Row.Cells[0].FindControl("DropDownList1");
ddl.Items.Add("S");
}
if (size.Contains("m"))
{
DropDownList ddl = (DropDownList)FormView_Product.Row.Cells[0].FindControl("DropDownList1");
ddl.Items.Add("M");
}
if (size.Contains("f"))
{
DropDownList ddl = (DropDownList)FormView_Product.Row.Cells[0].FindControl("DropDownList1");
ddl.Items.Add("Freesize");
}
return null;
}
protected string FormattedGetSize(String Size)
{
DropDownList ddl = (DropDownList)FormView_Product.Row.Cells[0].FindControl("DropDownList1");
string selectedSize = ddl.SelectedItem.ToString();
return selectedSize;
}
它不起作用的原因是。。"你做错了"。您期望<a href=..
将根据用户交互进行更改,但它在用户收到页面时已经生成。如果你想根据下拉列表更改链接,你必须有以下任一项:
- 在下拉列表中选择回发,则链接将更改
- 您可以通过在下拉选择中附加事件来使用一些javascript更改
href
您在Page_Load方法中做什么?您是否检查当前请求是否是post-back(使用IsPostBack(?如果是,请检查IsPostBack,并仅在Get请求时将DropDownList绑定到基础数据源。