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

管理菜品的界面

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

<asp:TableRow runat="server">

<asp:TableCell runat="server">菜品名称</asp:TableCell>

<asp:TableCell runat="server">菜品介绍</asp:TableCell>

<asp:TableCell runat="server">菜品详情</asp:TableCell>

<asp:TableCell runat="server">菜系</asp:TableCell>

<asp:TableCell runat="server">菜品图片路径</asp:TableCell>

</asp:TableRow>

<asp:TableRow runat="server">

<asp:TableCell runat="server"><input type = "text" style ="width: 80%" id="newDishName" runat="server" /></asp:TableCell>

<asp:TableCell runat="server"><input type = "text" style ="width: 80%" id="newDishIntro" runat="server" /></asp:TableCell>

<asp:TableCell runat="server"><input type = "text" style ="width: 80%" id="newDishDetails" runat="server" /></asp:TableCell>

<asp:TableCell runat="server"><input type = "text" style ="width: 80%" id="newDishType" runat="server" /></asp:TableCell>

<asp:TableCell runat="server"><input type = "text" style ="width: 80%" id="newDishPic" runat="server" /></asp:TableCell>

</asp:TableRow>

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("<script>alert(\"命令"+sql+"运行失败\")</script>");

}

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);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值