我有2個下拉列表,我需要一個默認值顯示爲第一個項目,但隨後的ddlSize沒有得到默認值之一,我也試圖建立2個獨立的功能TypeColor & TypeSize但它沒有幫助,有什麼建議嗎?謝謝:已經2下拉列表問題
<asp:DropDownList ID="ddlColor" OnDataBinding='<%# TypeSelection((int)Eval("ProductID")) %>' runat="server" Width="109">
<asp:ListItem Value="Select Color "></asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="ddlSize" OnDataBinding='<%# TypeSelection((int)Eval("ProductID")) %>' runat="server" Width="109">
<asp:ListItem Value="Select Size "></asp:ListItem>
</asp:DropDownList>
protected string TypeSelection(int pID)
{
DropDownList ddlColor = (DropDownList)FormView_Product.Row.Cells[0].FindControl("ddlColor");
DropDownList ddlSize = (DropDownList)FormView_Product.Row.Cells[0].FindControl("ddlSize");
CommerceEntities db = new CommerceEntities();
ddlColor.DataSource = from p in db.ProductTypes
where p.ProductID == pID
orderby p.Color
select new { p.ProductID, p.Color };
ddlColor.DataTextField = "Color";
ddlColor.Items.Insert(0, new ListItem("Select Color", "NA")); //----->Default value
ddlSize.DataSource = from p in db.ProductTypes
where p.ProductID == pID
orderby p.Size descending
select new { p.ProductID, p.Size };
ddlSize.DataTextField = "Size";
ddlSize.Items.Insert(0, new ListItem("Select Size", "NA")); //----->Default value(can't get this into the DDL.)
return null;
}
我認爲這是一個最好的方法。 – Tocco