后台代码:
public partial class Manage_Product : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
void Bind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["GetConnection"].ToString());
SqlCommand cmd = new SqlCommand("select * from Product_Category where pid=-1", con);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ParentRp.DataSource = ds;
ParentRp.DataBind();
con.Close();
}
protected void ParentRp_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
HiddenField hd = e.Item.FindControl("HiddenField1") as HiddenField;
int num = Convert.ToInt32(hd.Value.ToString());
SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["GetConnection"].ToString());
SqlCommand cm = new SqlCommand("select * from [Product_Category] where pid=@id", sc);
cm.CommandType = CommandType.Text;
cm.Parameters.Add("@id", SqlDbType.Int).Value = num;
sc.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cm;
DataSet ds = new DataSet();