我的编辑和删除都使用的是内置的commandfiled
我的绑源都没有使用数据源控件 都是自己代码写的,
点击编辑按钮出现更新和取消但是原来的删除就消失了~只是看不见 ,如何让删除不消失呢,坐等求解~!
为什么要显示出来?本来编辑的时候就就应该只出现更新的取消按钮啊
需求让显示出来,请问怎么办??
@阿耒: 如果这样的话建议自己写,不用gridView自带的处理方式
我用的gridview自带的处理方式了,只要稍微改一下就OK了,谢谢你了
给你一个Formview处理的代码,大同小异.
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindData(); } } private void BindData() { ERPProjectMange.Architecture Architecture = new ERPProjectMange.Architecture(); Architecture.Category = int.Parse(Request.QueryString["category"].ToString()); DataTable dt = new DataTable(); if (Request.QueryString["DataID"] != null) { //只读模式 if (Request.QueryString["DataID"].ToString() != string.Empty) { Architecture.ID = int.Parse(Request.QueryString["DataID"].ToString()); dt = Architecture.GetERPZJArchitectureWithID(); } } else { Architecture.Bianhao = int.Parse(Request.QueryString["id"].ToString()); dt = Architecture.GetERPZJArchitecture(); if (dt.Rows.Count > 0) { //新增模式 FormView1.ChangeMode(FormViewMode.Insert); } } if (dt.Rows.Count > 0) { FormView1.ChangeMode(FormView1.CurrentMode); FormView1.DataSource = dt; FormView1.DataBind(); SetLblText("xmname", dt.Rows[0]["xmname"].ToString()); SetLblText("category", ((BusinessName)int.Parse(Request.QueryString["category"].ToString())).ToString()); if (FormView1.CurrentMode == FormViewMode.Insert) { SetLblText("signdate", DateTime.Now.ToString()); } SetLblText("jiafang", dt.Rows[0]["kfname"].ToString()); } } protected void FormView1_ModeChanging(object sender, FormViewModeEventArgs e) { FormView1.ChangeMode(e.NewMode); BindData(); } protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) { if (Request.QueryString["DataID"] != null) { if (Request.QueryString["DataID"].ToString() != string.Empty) { ERPProjectMange.Architecture Arch = new ERPProjectMange.Architecture(); Arch.ID = int.Parse(Request.QueryString["DataID"].ToString()); Arch.Totalarea = GetLblText("totalareaTextBox"); Arch.Upfloornum = GetLblText("upfloornumTextBox"); Arch.Standhigh = GetLblText("standhighTextBox"); Arch.Downarea = GetLblText("downareaTextBox"); Arch.Downfloornum = GetLblText("downfloornumTextBox"); Arch.Span = GetLblText("SpanTextBox"); Arch.Structuretype = GetLblText("StructuretypeTextBox"); Arch.Projecttype = GetLblText("ProjecttypeTextBox"); Arch.Largeearthwork = GetLblText("LargeearthworkTextBox"); Arch.Projectlocation = GetLblText("ProjectlocationTextBox"); Arch.Constructionunit = GetLblText("ConstructionunitTextBox"); Arch.Basics = GetLblText("BasicsTextBox"); Arch.Buildingground = GetLblText("BuildinggroundTextBox"); Arch.Exteriorwall = GetLblText("ExteriorwallTextBox"); Arch.Innerwall = GetLblText("InnerwallTextBox"); Arch.Outsidewall = GetLblText("OutsidewallTextBox"); Arch.Innerwallface = GetLblText("InnerwallfaceTextBox"); Arch.Ceiling = GetLblText("CeilingTextBox"); Arch.Beam = GetLblText("beamTextBox"); Arch.Roofing = GetLblText("RoofingTextBox"); Arch.Windows = GetLblText("windowsTextBox"); Arch.ArchitectureOther = GetLblText("ArchitectureOtherTextBox"); Arch.Watersupply = GetLblText("WatersupplyTextBox"); Arch.Drainage = GetLblText("DrainageTextBox"); Arch.Electrical = GetLblText("ElectricalTextBox"); Arch.Firecontrol = GetLblText("FirecontrolTextBox"); Arch.InstallationOther = GetLblText("InstallationOtherTextBox"); if (Arch.UpdateERPZJArchitecture()) { FormView1.ChangeMode(FormViewMode.ReadOnly); BindData(); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "adow", "<script type=\"text/javascript\">alert('保存失败,请重试!')</script>"); } } } } protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e) { ERPProjectMange.Architecture Arch = new ERPProjectMange.Architecture(); Arch.Bianhao = int.Parse(Request.QueryString["id"].ToString()); Arch.Category = int.Parse(Request.QueryString["category"].ToString()); Arch.Signdate = DateTime.Parse(GetLblText("signdate")); Arch.Totalarea = GetLblText("totalareaTextBox"); Arch.Upfloornum = GetLblText("upfloornumTextBox"); Arch.Standhigh = GetLblText("standhighTextBox"); Arch.Downarea = GetLblText("downareaTextBox"); Arch.Downfloornum = GetLblText("downfloornumTextBox"); Arch.Span = GetLblText("SpanTextBox"); Arch.Structuretype = GetLblText("StructuretypeTextBox"); Arch.Projecttype = GetLblText("ProjecttypeTextBox"); Arch.Largeearthwork = GetLblText("LargeearthworkTextBox"); Arch.Projectlocation = GetLblText("ProjectlocationTextBox"); Arch.Constructionunit = GetLblText("ConstructionunitTextBox"); Arch.Basics = GetLblText("BasicsTextBox"); Arch.Buildingground = GetLblText("BuildinggroundTextBox"); Arch.Exteriorwall = GetLblText("ExteriorwallTextBox"); Arch.Innerwall = GetLblText("InnerwallTextBox"); Arch.Outsidewall = GetLblText("OutsidewallTextBox"); Arch.Innerwallface = GetLblText("InnerwallfaceTextBox"); Arch.Ceiling = GetLblText("CeilingTextBox"); Arch.Beam = GetLblText("beamTextBox"); Arch.Roofing = GetLblText("RoofingTextBox"); Arch.Windows = GetLblText("windowsTextBox"); Arch.ArchitectureOther = GetLblText("ArchitectureOtherTextBox"); Arch.Watersupply = GetLblText("WatersupplyTextBox"); Arch.Drainage = GetLblText("DrainageTextBox"); Arch.Electrical = GetLblText("ElectricalTextBox"); Arch.Firecontrol = GetLblText("FirecontrolTextBox"); Arch.InstallationOther = GetLblText("InstallationOtherTextBox"); int newid = Arch.AddERPZJArchitecture(); if (newid > 0) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "setid", "<script type=\"text/javascript\">parent.window.setnewid(" + newid.ToString() + ");</script>"); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "adow", "<script type=\"text/javascript\">alert('保存失败,请重试!')</script>"); } }
不懂,可不可以详细说说我那个问题怎么实现
@阿耒: 首先是这样的,编辑时要删除干什么?实在想要也可以,自己在 <EditItemTemplate>里加上<DELCommand即可>
<asp:TemplateField HeaderText="删除" HeaderStyle-Width="50px">
<ItemTemplate>
<asp:LinkButton ID="LinkDel" ForeColor="red" runat="server" CommandName="Delete" OnClientClick="javascript:return confirm('确认要删除?');">删除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
//删除
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value);
sql = "delete from typeb where id= " + id;
if (ManageDAL.Edit(sql, CommandType.Text))
{
Show();
}
}