当前位置: 首页 > >

订餐网站4(管理界面->dishes.aspx)

发布时间:

管理菜品的界面


1. 添加菜品通过 table中添加input text box实现



菜品名称


菜品介绍


菜品详情


菜系


菜品图片路径










2. 下面的展现通过bind gridview实现


3. 实现后效果



4.cs文件


using System;


using System.Collections.Generic;


using System.Web;


using System.Web.UI;


using System.Web.UI.WebControls;


using System.Web.UI.HtmlControls;


using System.Reflection;


using System.Data;


using Common;


public partial class Admin_dishes : System.Web.UI.Page


{


protected void Page_Load(object sender, EventArgs e)


{


DataTable dt = dbOperation.GetAllDishes2();


this.GridViewDishes.DataSource = dt;


this.GridViewDishes.DataBind();


}


protected void GridViewDishes_RowEditing(object sender, GridViewEditEventArgs e)


{


this.GridViewDishes.EditIndex = e.NewEditIndex;


this.GridViewDishes.DataBind();


}


protected void GridViewDishes_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)


{


this.GridViewDishes.EditIndex = -1;


this.GridViewDishes.DataBind();


}


protected void GridViewDishes_RowUpdating(object sender, GridViewUpdateEventArgs e)


{


string id = this.GridViewDishes.Rows[e.RowIndex].Cells[0].Text;


string dishName = ((System.Web.UI.WebControls.TextBox)(this.GridViewDishes.Rows[e.RowIndex].Cells[1].Controls[0])).Text;


string intro = ((System.Web.UI.WebControls.TextBox)(this.GridViewDishes.Rows[e.RowIndex].Cells[2].Controls[0])).Text;


string details = ((System.Web.UI.WebControls.TextBox)(this.GridViewDishes.Rows[e.RowIndex].Cells[3].Controls[0])).Text;


string sql = "update dish set dishName = + dishName + ,intro = + intro + ,details = + details + where dishId =" + id;


ExcuteSql(sql);


}


protected void GridViewDishes_RowDeleting(object sender, GridViewDeleteEventArgs e)


{


string id = this.GridViewDishes.Rows[e.RowIndex].Cells[0].Text;


string sql = "delete * from dish where dishId =" + id;


ExcuteSql(sql);


}


private void ExcuteSql(string sql)


{


if (dbOperation.ExcuteSql(sql) == -1)


{


Response.Write("");


}


this.GridViewDishes.EditIndex = -1;


DataTable dt = dbOperation.GetAllDishes2();


this.GridViewDishes.DataSource = dt;


this.GridViewDishes.DataBind();


}


protected void ButtonAdd_Click(object sender, EventArgs e)


{


string dishName = this.newDishName.Value;


string intro = this.newDishIntro.Value;


string details = this.newDishDetails.Value;


string type = this.newDishType.Value;


string pic = this.newDishPic.Value;


string sql = "Insert into dish(dishName,intro,details,type,pic) Values( + dishName + , + intro + , + details + , + type + , + pic + )";


ExcuteSql(sql);


}


}



友情链接: