管理菜品的界面

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(管理界面->dishes.aspx)

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

}

}

相关文章:

  • 2021-05-11
  • 2021-11-23
  • 2021-06-12
  • 2021-10-24
  • 2021-11-02
  • 2021-12-04
  • 2021-05-05
猜你喜欢
  • 2021-06-18
  • 2021-11-17
  • 2021-11-17
  • 2022-12-23
  • 2021-08-16
  • 2021-11-15
相关资源
相似解决方案