关于GridView的添加 修改 删除

前台:

<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="GridView.aspx.cs"Inherits="WebApplication2.GridView"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<inputtype="button"onclick="location.href='infoset.aspx';"value="添加"/>
</div>
<div>
<asp:GridViewrunat="server"ID="g1"AutoGenerateColumns="false">
<Columns>
<asp:BoundFieldDataField="id"HeaderText="ID"/>
<asp:BoundFieldHeaderText="姓名"DataField="uname"/>
<asp:BoundFieldHeaderText="学号"DataField="code"/>
<asp:BoundFieldHeaderText="学校"DataField="school"/>
<asp:TemplateField>
<ItemTemplate>
<ahref="infoset.aspx?id=<%#Eval("id")%>">修改</a>
<asp:LinkButtonrunat="server"ID="btn_del"Text="删除"CommandName="del"CommandArgument='<%#Eval("id")%>'OnClientClick="returnconfirm('确定删除吗?')?"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<%--<webdiyer:AspNetPagerID="AspNetPager1"PageSize="12"runat="server">
</webdiyer:AspNetPager>--%>

</form>
</body>
</html>

后台C#:

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;

usingSystem.Data;
usingSystem.Data.SqlClient;


namespaceWebApplication2
{
publicpartialclassGridView:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!IsPostBack)
{
bindgrid();
}
}
protectedoverridevoidOnInit(EventArgse)
{
g1.RowCommand+=g1_RowCommand;
//AspNetPager1.PageChanging+=AspNetPager1_PageChanging;
base.OnInit(e);
}
//voidAspNetPager1_PageChanging(objectsrc,Wuqi.Webdiyer.PageChangingEventArgse)
//{
//bindgrid();
//}

voidg1_RowCommand(objectsender,GridViewCommandEventArgse)
{

if(e.CommandName=="del")
{
blltest.bllStudent.delete(Convert.ToInt32(e.CommandArgument));
bindgrid();
}
}
voidbindgrid()
{
introwcount;
//blltest.bllStudent.ReadData(AspNetPager1.CurrentPageIndex,AspNetPager1.PageSize,outrowcount);
//AspNetPager1.RecordCount=rowcount;
DataTabledt=blltest.bllStudent.ReadDataAll();
this.g1.DataSource=dt;
this.g1.DataBind();
}
}
}

你可能感兴趣的:(删除,修改,GridView的添加)