0
我有一個動態綁定網格視圖的內容頁面。我還添加了編輯和刪除按鈕。但點擊編輯按鈕時,如何生成更新和取消鏈接按鈕。在點擊asp.net中的編輯按鈕時生成更新和取消按鈕
我知道它必須在RowEditing Event中處理。請詳細說明如何獲取這些按鈕。 這裏是ap.net網頁
<%@ Page Title="" Language="C#" MasterPageFile="~/ManageSMS.Master" AutoEventWireup="true" CodeBehind="WebForm10.aspx.cs" Inherits="SMS_Mod2.WebForm10" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
<asp:Panel ID="Panel1" Visible="false" runat="server"><asp:DropDownList ID="DropDownList2" AutoPostBack="true" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" runat="server"></asp:DropDownList></asp:Panel>
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:CommandField ShowDeleteButton ="true" />
<asp:CommandField ShowEditButton="true" />
</Columns>
</asp:GridView>
</asp:Content>
這裏是代碼隱藏文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BOL;
using DAL;
namespace SMS_Mod2
{
public partial class WebForm10 : System.Web.UI.Page
{
StationaryManagement stMgmt = new StationaryManagement();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Add(new ListItem("All", "0"));
DropDownList1.Items.Add(new ListItem("Branch", "1"));
//DropDownList1.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if(DropDownList1.SelectedIndex != 0)
{
Panel1.Visible = true;
DropDownList2.DataSource = stMgmt.ViewBranches();
DropDownList2.DataTextField = "BranchName";
DropDownList2.DataValueField = "BranchID";
DropDownList2.DataBind();
DropDownList2.Items.Add(new ListItem("Please select", "0"));
}
else
{
Panel1.Visible = false;
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.DataSource = stMgmt.ViewLocations(DropDownList2.SelectedIndex);
GridView1.DataBind();
GridView1.AllowSorting = true;
GridView1.AutoGenerateEditButton = true;
GridView1.AutoGenerateDeleteButton = true;
}
}
}