【发布时间】:2011-04-06 20:20:36
【问题描述】:
我有datalist 和ddl,用户可以从ddl 中选择值来绑定datalist。当我尝试在用户选择值时在datalist 中找到ddl 时,出现此错误
索引超出范围。一定是 非负且小于 集合。参数名称:索引
这里
DDLProduct2 = (DropDownList)DLProduct.Items[DLProduct.EditItemIndex].FindControl("DDlProduct");
所以请任何人帮助我。
private DropDownList DDLProduct2;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ProductByProductID();
CategoryParentZero();
}
}
protected void DDlProduct_SelectedIndexChanged(object sender, EventArgs e)
{
DDLProduct2 = (DropDownList)DLProduct.Items[DLProduct.EditItemIndex].FindControl("DDlProduct");
if (DDLProduct2 != null)
{
if (DDLProduct2.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 = DDLProduct2.SelectedValue;
;
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(dt);
DLProduct.DataSource = dt;
DLProduct.DataBind();
}
}
}
}
【问题讨论】:
标签: asp.net drop-down-menu datalist