62,271
社区成员
发帖
与我相关
我的任务
分享
SqlDatacategory.SelectCommand = "SELECT [id], [Raid], [categoryname], [parentid], [parentname] FROM [category] order by [Raid],[id]";
GridView1.DataSourceID = "SqlDatacategory";
GridView1.DataBind();
protected void Button1_Click(object sender, EventArgs e)
{
if (Button1.Text == "添加")
{
if (Raids.SelectedValue == "1")
{
string categoryname = TextBox1.Text;
string addsql = "insert into category (Raid,categoryname)values(1,'" + categoryname + "')";
sqldata.ExecuteSql(addsql);
TextBox1.Text = "";
Panel1.Visible = false;
GridView1.DataBind();
}
else
{
if (Raids.SelectedValue == "2")
{
string categoryname = TextBox1.Text;
string parentname = categoryList.SelectedItem.Text;
string parentid = categoryList.SelectedValue.ToString();
string addsql = "insert into category (Raid,categoryname,parentid,parentname)values(2,'" + categoryname + "','" + parentid + "','" + parentname + "')";
sqldata.ExecuteSql(addsql);
TextBox1.Text = "";
Label1.Visible = false;
categoryList.Visible = false;
Panel1.Visible = false;
GridView1.DataBind();
}
}
}
else
{
if (Button1.Text == "修改")
{
if (Raids.SelectedValue == "1")
{
int cid = Convert.ToInt16(Label2.Text);
string categoryname = TextBox1.Text;
string addsql = "update category set [Raid]=1,[categoryname]='" + categoryname + "' where [id]=" + cid;
sqldata.ExecuteSql(addsql);
TextBox1.Text = "";
Panel1.Visible = false;
GridView1.DataBind();
}
else
{
if (Raids.SelectedValue == "2")
{
int cid = Convert.ToInt16(Label2.Text);
string categoryname = TextBox1.Text;
string parentname = categoryList.SelectedItem.Text;
string parentid = categoryList.SelectedValue.ToString();
string addsql = "update category set [Raid]=2,[categoryname]='" + categoryname + "',[Parentid]='" + parentid + "',[Parentname]='" + parentname + "' where [id]=" + cid;
sqldata.ExecuteSql(addsql);
TextBox1.Text = "";
Label1.Visible = false;
categoryList.Visible = false;
Panel1.Visible = false;
GridView1.DataBind();
}
}
}
}
}
GridView.DataBind();