下面是repater绑定及插入属性商品,选中多个插入后数据还是为1,不选正确 repater里不可用for循环、遍历
/// <summary>
/// 商品属性数据库绑定
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rptProperty_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblID = (Label)e.Item.FindControl("lbPID");
Label lblInputType = (Label)e.Item.FindControl("lbInputType");
TextBox txt = (TextBox)e.Item.FindControl("txtRptValue");
DropDownList ddl = (DropDownList)e.Item.FindControl("ddlRptValue");
CheckBoxList cb = (CheckBoxList)e.Item.FindControl("CheckBoxListproperty") as CheckBoxList;//++ 2011-11-15
if (lblInputType.Text == "0")
{
ddl.Visible = false;
cb.Visible = false;
}
else if (lblInputType.Text == "2")//+++ 2011-11-15
{
ddl.Visible = false;
txt.Visible = false;
DataTable dt = DatabaseProvider.GetInstance().GetPropertyValueByPropertyID(lblID.Text);
if (dt.Rows.Count > 0)
{
cb.DataSource = dt;
cb.DataBind();
}
}
else
{
cb.Visible = false;
txt.Visible = false;
DataTable dt = DatabaseProvider.GetInstance().GetPropertyValueByPropertyID(lblID.Text);
ddl.DataSource = dt;
ddl.DataBind();
} if (id != "0")
if (lblInputType.Text == "0") txt.Text = DatabaseProvider.GetInstance().GetPropertyValuePlus(id, lblID.Text);
else if (lblInputType.Text == "2")
{
foreach (ListItem li in cb.Items)//++ 2011-11-16
{
DataTable dt = DatabaseProvider.GetInstance().GetProductValueByProductID(id);
foreach (DataRow dr in dt.Rows)
{
if (li.Value == dr["ValueID"].ToString())
{
if (li.Value.Trim() != "")
{
cb.SelectedValue = li.Value;
break;
}
}
}
} }
else
{
foreach (ListItem li in ddl.Items)
{
DataTable dt = DatabaseProvider.GetInstance().GetProductValueByProductID(id);
string ids = "";
foreach (DataRow dr in dt.Rows)
{
if (li.Value == dr["ValueID"].ToString())
{
if (li.Value.Trim() != "")
{
ddl.SelectedValue = li.Value;
break;
}
}
}
}
}
}
} /// <summary>
/// 插入属性商品
/// </summary>
/// <param name="id"></param>
private void ProcessPropertyList(string productid)
{
//插入之前先删除所有扩展属性
DatabaseProvider.GetInstance().DeleteProductValue(productid);
DatabaseProvider.GetInstance().DeletePorpertyValuePlus(productid); foreach (RepeaterItem i in rptProperty.Items)
{
DropDownList ddl = (DropDownList)i.FindControl("ddlRptValue");
TextBox txt = (TextBox)i.FindControl("txtRptValue");
CheckBoxList cb = (CheckBoxList)i.FindControl("CheckBoxListproperty") as CheckBoxList;//++ 2011-11-16
if (ddl.SelectedValue.Length > 0) // 下拉列表
{
ProductValue info = new ProductValue();
info.ProductID = int.Parse(productid);
info.ValueID = int.Parse(ddl.SelectedValue);
info.IsSelect = 1;
DatabaseProvider.GetInstance().InsertProductValue(info);
}
if (txt.Text.Length > 0) //手工填写
{
Label lblID = (Label)i.FindControl("lbPID");
DatabaseProvider.GetInstance().InsertProperyValuePlus(lblID.Text, productid, utils.CheckStr(txt.Text.Trim()));
} if (cb.SelectedValue.Length > 0)//++ 2011-11-16 复选
{
ProductValue info = new ProductValue();
info.ProductID = int.Parse(productid);
info.ValueID = int.Parse(cb.SelectedValue);
info.IsSelect = 1;
DatabaseProvider.GetInstance().InsertProductValue(info); //string name = utils.CheckStr(this.txtSelfProperty.Text);
//string value = utils.CheckStr(this.txtSelfPropertyValue.Text);
//ProductProperty info = new ProductProperty();
//info.Name = name;
//info.Value = value;
//info.IsInOrder = 0;
//info.ProductID = int.Parse(id);
//DatabaseProvider.GetInstance().InsertPropertyByProductId(info);
}
}
}
/// <summary>
/// 商品属性数据库绑定
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rptProperty_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblID = (Label)e.Item.FindControl("lbPID");
Label lblInputType = (Label)e.Item.FindControl("lbInputType");
TextBox txt = (TextBox)e.Item.FindControl("txtRptValue");
DropDownList ddl = (DropDownList)e.Item.FindControl("ddlRptValue");
CheckBoxList cb = (CheckBoxList)e.Item.FindControl("CheckBoxListproperty") as CheckBoxList;//++ 2011-11-15
if (lblInputType.Text == "0")
{
ddl.Visible = false;
cb.Visible = false;
}
else if (lblInputType.Text == "2")//+++ 2011-11-15
{
ddl.Visible = false;
txt.Visible = false;
DataTable dt = DatabaseProvider.GetInstance().GetPropertyValueByPropertyID(lblID.Text);
if (dt.Rows.Count > 0)
{
cb.DataSource = dt;
cb.DataBind();
}
}
else
{
cb.Visible = false;
txt.Visible = false;
DataTable dt = DatabaseProvider.GetInstance().GetPropertyValueByPropertyID(lblID.Text);
ddl.DataSource = dt;
ddl.DataBind();
} if (id != "0")
if (lblInputType.Text == "0") txt.Text = DatabaseProvider.GetInstance().GetPropertyValuePlus(id, lblID.Text);
else if (lblInputType.Text == "2")
{
foreach (ListItem li in cb.Items)//++ 2011-11-16
{
DataTable dt = DatabaseProvider.GetInstance().GetProductValueByProductID(id);
foreach (DataRow dr in dt.Rows)
{
if (li.Value == dr["ValueID"].ToString())
{
if (li.Value.Trim() != "")
{
cb.SelectedValue = li.Value;
break;
}
}
}
} }
else
{
foreach (ListItem li in ddl.Items)
{
DataTable dt = DatabaseProvider.GetInstance().GetProductValueByProductID(id);
string ids = "";
foreach (DataRow dr in dt.Rows)
{
if (li.Value == dr["ValueID"].ToString())
{
if (li.Value.Trim() != "")
{
ddl.SelectedValue = li.Value;
break;
}
}
}
}
}
}
} /// <summary>
/// 插入属性商品
/// </summary>
/// <param name="id"></param>
private void ProcessPropertyList(string productid)
{
//插入之前先删除所有扩展属性
DatabaseProvider.GetInstance().DeleteProductValue(productid);
DatabaseProvider.GetInstance().DeletePorpertyValuePlus(productid); foreach (RepeaterItem i in rptProperty.Items)
{
DropDownList ddl = (DropDownList)i.FindControl("ddlRptValue");
TextBox txt = (TextBox)i.FindControl("txtRptValue");
CheckBoxList cb = (CheckBoxList)i.FindControl("CheckBoxListproperty") as CheckBoxList;//++ 2011-11-16
if (ddl.SelectedValue.Length > 0) // 下拉列表
{
ProductValue info = new ProductValue();
info.ProductID = int.Parse(productid);
info.ValueID = int.Parse(ddl.SelectedValue);
info.IsSelect = 1;
DatabaseProvider.GetInstance().InsertProductValue(info);
}
if (txt.Text.Length > 0) //手工填写
{
Label lblID = (Label)i.FindControl("lbPID");
DatabaseProvider.GetInstance().InsertProperyValuePlus(lblID.Text, productid, utils.CheckStr(txt.Text.Trim()));
} if (cb.SelectedValue.Length > 0)//++ 2011-11-16 复选
{
ProductValue info = new ProductValue();
info.ProductID = int.Parse(productid);
info.ValueID = int.Parse(cb.SelectedValue);
info.IsSelect = 1;
DatabaseProvider.GetInstance().InsertProductValue(info); //string name = utils.CheckStr(this.txtSelfProperty.Text);
//string value = utils.CheckStr(this.txtSelfPropertyValue.Text);
//ProductProperty info = new ProductProperty();
//info.Name = name;
//info.Value = value;
//info.IsInOrder = 0;
//info.ProductID = int.Parse(id);
//DatabaseProvider.GetInstance().InsertPropertyByProductId(info);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货