在动态绑定的DropDownlist的最前面加上一个空白项或“全部”
前端代码Html层
<asp:DropDownList id="ddltItem" runat="server" DataTextField="ItemName" DataValueField="ItemNO"></asp:DropDownList>
CS代码层
public void SelectItem(int i)
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
string mySelectQuery =
"select ItemNO,ItemName from ts_AO_Item order by ItemNO";
SqlDataAdapter myCommand = new SqlDataAdapter(mySelectQuery,myConnection);
myConnection.Open();
DataSet ds = new DataSet();
myCommand.Fill(ds,"data");
AddxmDs(ds);
item.DataSource=ds.Tables["data"].DefaultView;
item.DataBind();
myConnection.Close();
}
private void AddxmDs(DataSet ds)
{
ds.Tables[0].Rows[0]["ItemNO"]="-1";
ds.Tables[0].Rows[0]["ItemName"]="- 全部 -";
}