namespace Components
{
public class ProductsTypeDropDownList:DropDownList
{
DAL.ProductType dalprod = new DAL.ProductType();
public ProductsTypeDropDownList()
{
this.Items.Add(new ListItem("请选择", ""));
List<Model.ProductType> listProc = dalprod.GetProductType();
foreach (Model.ProductType p in listProc)
{
this.Items.Add(new ListItem(p.Typename,p.Typeid.ToString()));
}
}
}
}
namespace DAL
{
public class ProductType
{
public List<Model.ProductType> GetProductType()
{
List<Model.ProductType> list = new List<Model.ProductType>();
string strText = "select * from ProductType";
SqlDataReader dr = DBUtility.SqlHelper.ExecuteReader(CommandType.Text, strText, null);
while (dr.Read())
{
Model.ProductType protype = new Model.ProductType(dr.GetString(1), dr.GetInt32(0));
list.Add(protype);
}
return list;
}
}
}
<%@ Register Assembly="Components" Namespace="Components" TagPrefix="cc" %>
<cc:ProductNameDropDownList ID="ProcTypeName" runat="server"></cc:ProductNameDropDownList>