0
我在数据列表有DDL,当我试图从DDL这个误差值绑定数据列表apeared(对象refrence没有设置...)这里DDLProduct.SelectedIndex错误时绑定DataList控件与值从DDL
public DropDownList DDLProduct;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DLProduct_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DDLProduct = e.Item.FindControl("DDlProduct") as DropDownList;
DDLProduct.Items.Insert(0, new ListItem("Swithch Model", "0"));
}
}
protected void DDlProduct_SelectedIndexChanged(object sender, EventArgs e)
{
if (DDLProduct.SelectedIndex > 0)
{
using
(SqlConnection conn = Connection.GetConnection())
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_GetProductsByProductID";
SqlParameter ParentID_Param = cmd.Parameters.Add("@ProductID", SqlDbType.Int);
ParentID_Param.Value = DDLProduct.SelectedValue;
;
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
DLProduct.DataSource = dt;
DLProduct.DataBind();
}
}
}
完整例外,行进线将是有益的,还有ASPX定义。 – asawyer 2011-04-06 14:36:35