我正在尝试格式化下拉列表的文本,但似乎没有任何效果。下面是我的代码:
下拉列表:
<asp:DropDownList runat="server" ID="ddlSalary" CssClass="ddlBox"
CausesValidation="true" AutoPostBack="true"
onselectedindexchanged="ddlSalary_SelectedIndexChanged" />
后面的代码:
if (!IsPostBack)
{
ddlSalary.DataSource = Placements.DropDownPopulating("Placement_Salary_From");
ddlSalary.DataBind();
ddlSalary.Items.Insert(0, new ListItem("-- Salary --", "0"));
结果:
6.0000
200.0000
1000.0000
但我想:
£6
£200
£1000
我试过使用:
ddlSalary.DataTextFormatString = "{0:C}";
编辑
填充下拉列表:
public static List<string> DropDownPopulating(string selectedFilter)
{
List<string> returnVal = new List<string> { };
using (SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["websiteContent"].ConnectionString))
{
sqlCon.Open();
string SQL = "SELECT DISTINCT " + selectedFilter + " FROM Placements";
using (var CMD = new SqlCommand(SQL, sqlCon))
{
using (var DR = CMD.ExecuteReader())
{
while (DR.Read())
{
returnVal.Add(DR[selectedFilter].ToString());
}
}
}
sqlCon.Close();
}
return returnVal;
}