1 使用自定义列显示班级学生信息,要求能够进 行删除和修改,删除时给出提示:如 “ 确信要删 除 - 张三 - 吗? ” ,其中张三为当前行的姓名
2012-12-05 19:24
691 查看
前台代码:
<%@ Page Xlanguage="C#" AutoEventWireup="true" CodeBehind="GradView1.aspx.cs" Inherits="_12_05GridView.GradView1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style10
{
height: 17px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="sid" DataSourceID="SqlDataSource1" EmptyDataText="没有数据"
Font-Bold="True" Font-Size="Small" ForeColor="#333333" GridLines="None"
Height="40px" ShowFooter="True" Width="712px"
Xonrowcommand="GridView1_RowCommand" Xonrowdatabound="GridView1_RowDataBound"
style="margin-right: 81px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="sid" HeaderText="编号" InsertVisible="False"
ReadOnly="True" SortExpression="sid" />
<asp:HyperLinkField DataNavigateUrlFields="photo"
DataNavigateUrlFormatString="viewPhoto.aspx?photourl={0}" DataTextField="sname"
DataTextFormatString="点击查看{0}" HeaderText="姓名" Target="_blank"
NavigateUrl="~/viewPhoto.aspx" />
<asp:BoundField DataField="sex" HeaderText="性别" SortExpression="sex" />
<asp:BoundField DataField="age" HeaderText="年龄" SortExpression="age" />
<asp:CheckBoxField DataField="isking" HeaderText="是否班长"
SortExpression="isking" />
<asp:TemplateField HeaderText="照片">
<ItemTemplate>
<table style="width:100%;">
<tr>
<td><a href='viewPhoto.aspx?photourl=<%#Eval("photo") %>' target="_blank">姓名:<%#Eval("sname") %></a></td>
</tr>
<tr>
<td class="style10">
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("photo") %>' Width="60px" Height="60px" ToolTip='<%#"这是:"+Eval("sname")%>'/>
</td>
</tr>
<tr>
<td>编号:<%#Eval("sid") %> 年龄:<%#Eval("age") %> </td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField HeaderText="删除" Text="删除" />
<asp:ButtonField CommandName="initialPassword" Text="初始化密码" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center"
VerticalAlign="Middle" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<div>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:studentConnectionString %>"
DeleteCommand="DELETE FROM [student] WHERE [sid] = @sid"
InsertCommand="INSERT INTO [student] ([sname], [classid], [sex], [age], [isking], [photo]) VALUES (@sname, @classid, @sex, @age, @isking, @photo)"
SelectCommand="SELECT [sid], [sname], [classid], [sex], [age], [isking], [photo] FROM [student]"
UpdateCommand="UPDATE [student] SET [sname] = @sname, [classid] = @classid, [sex] = @sex, [age] = @age, [isking] = @isking, [photo] = @photo WHERE [sid] = @sid">
<DeleteParameters>
<asp:Parameter Name="sid" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="sname" Type="String" />
<asp:Parameter Name="classid" Type="Int32" />
<asp:Parameter Name="sex" Type="String" />
<asp:Parameter Name="age" Type="Byte" />
<asp:Parameter Name="isking" Type="Boolean" />
<asp:Parameter Name="photo" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="sname" Type="String" />
<asp:Parameter Name="classid" Type="Int32" />
<asp:Parameter Name="sex" Type="String" />
<asp:Parameter Name="age" Type="Byte" />
<asp:Parameter Name="isking" Type="Boolean" />
<asp:Parameter Name="photo" Type="String" />
<asp:Parameter Name="sid" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _12_05GridView
{
public partial class GradView1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "initialPassword")//获取用户是点击了哪个按钮
{
//在这里写初始化的密码代码
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//可以在这个事件中处理已经完成的数据
//LinkButton lbtn = e.Row.Cells[6].Controls[0] as LinkButton;
if (e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
string sid=e.Row.Cells[0].Text;
HyperLink link = e.Row.Cells[1].Controls[0] as HyperLink;
LinkButton lbtn = e.Row.Cells[6].Controls[0] as LinkButton;
if (lbtn != null)
{
lbtn.Attributes.Add("onclick","return confirm('确定要删除编号为"+sid+"的"+link.Text+"吗?');");
}
}
}
}
2 使用模版列完成课上例子的实现,用一列显示 全部信息,同时完成修改的功能
<%@ Page Xlanguage="C#" AutoEventWireup="true" CodeBehind="GradView1.aspx.cs" Inherits="_12_05GridView.GradView1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style10
{
height: 17px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="sid" DataSourceID="SqlDataSource1" EmptyDataText="没有数据"
Font-Bold="True" Font-Size="Small" ForeColor="#333333" GridLines="None"
Height="40px" ShowFooter="True" Width="712px"
Xonrowcommand="GridView1_RowCommand" Xonrowdatabound="GridView1_RowDataBound"
style="margin-right: 81px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="sid" HeaderText="编号" InsertVisible="False"
ReadOnly="True" SortExpression="sid" />
<asp:HyperLinkField DataNavigateUrlFields="photo"
DataNavigateUrlFormatString="viewPhoto.aspx?photourl={0}" DataTextField="sname"
DataTextFormatString="点击查看{0}" HeaderText="姓名" Target="_blank"
NavigateUrl="~/viewPhoto.aspx" />
<asp:BoundField DataField="sex" HeaderText="性别" SortExpression="sex" />
<asp:BoundField DataField="age" HeaderText="年龄" SortExpression="age" />
<asp:CheckBoxField DataField="isking" HeaderText="是否班长"
SortExpression="isking" />
<asp:TemplateField HeaderText="照片">
<ItemTemplate>
<table style="width:100%;">
<tr>
<td><a href='viewPhoto.aspx?photourl=<%#Eval("photo") %>' target="_blank">姓名:<%#Eval("sname") %></a></td>
</tr>
<tr>
<td class="style10">
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("photo") %>' Width="60px" Height="60px" ToolTip='<%#"这是:"+Eval("sname")%>'/>
</td>
</tr>
<tr>
<td>编号:<%#Eval("sid") %> 年龄:<%#Eval("age") %> </td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField HeaderText="删除" Text="删除" />
<asp:ButtonField CommandName="initialPassword" Text="初始化密码" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center"
VerticalAlign="Middle" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<div>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:studentConnectionString %>"
DeleteCommand="DELETE FROM [student] WHERE [sid] = @sid"
InsertCommand="INSERT INTO [student] ([sname], [classid], [sex], [age], [isking], [photo]) VALUES (@sname, @classid, @sex, @age, @isking, @photo)"
SelectCommand="SELECT [sid], [sname], [classid], [sex], [age], [isking], [photo] FROM [student]"
UpdateCommand="UPDATE [student] SET [sname] = @sname, [classid] = @classid, [sex] = @sex, [age] = @age, [isking] = @isking, [photo] = @photo WHERE [sid] = @sid">
<DeleteParameters>
<asp:Parameter Name="sid" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="sname" Type="String" />
<asp:Parameter Name="classid" Type="Int32" />
<asp:Parameter Name="sex" Type="String" />
<asp:Parameter Name="age" Type="Byte" />
<asp:Parameter Name="isking" Type="Boolean" />
<asp:Parameter Name="photo" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="sname" Type="String" />
<asp:Parameter Name="classid" Type="Int32" />
<asp:Parameter Name="sex" Type="String" />
<asp:Parameter Name="age" Type="Byte" />
<asp:Parameter Name="isking" Type="Boolean" />
<asp:Parameter Name="photo" Type="String" />
<asp:Parameter Name="sid" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _12_05GridView
{
public partial class GradView1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "initialPassword")//获取用户是点击了哪个按钮
{
//在这里写初始化的密码代码
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//可以在这个事件中处理已经完成的数据
//LinkButton lbtn = e.Row.Cells[6].Controls[0] as LinkButton;
if (e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
string sid=e.Row.Cells[0].Text;
HyperLink link = e.Row.Cells[1].Controls[0] as HyperLink;
LinkButton lbtn = e.Row.Cells[6].Controls[0] as LinkButton;
if (lbtn != null)
{
lbtn.Attributes.Add("onclick","return confirm('确定要删除编号为"+sid+"的"+link.Text+"吗?');");
}
}
}
}
<%@ Page Xlanguage="C#" AutoEventWireup="true" CodeBehind="GradView1.aspx.cs" Inherits="_12_05GridView.GradView1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style10
{
height: 17px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="sid" DataSourceID="SqlDataSource1" EmptyDataText="没有数据"
Font-Bold="True" Font-Size="Small" ForeColor="#333333" GridLines="None"
Height="40px" ShowFooter="True" Width="712px"
Xonrowcommand="GridView1_RowCommand" Xonrowdatabound="GridView1_RowDataBound"
style="margin-right: 81px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="sid" HeaderText="编号" InsertVisible="False"
ReadOnly="True" SortExpression="sid" />
<asp:HyperLinkField DataNavigateUrlFields="photo"
DataNavigateUrlFormatString="viewPhoto.aspx?photourl={0}" DataTextField="sname"
DataTextFormatString="点击查看{0}" HeaderText="姓名" Target="_blank"
NavigateUrl="~/viewPhoto.aspx" />
<asp:BoundField DataField="sex" HeaderText="性别" SortExpression="sex" />
<asp:BoundField DataField="age" HeaderText="年龄" SortExpression="age" />
<asp:CheckBoxField DataField="isking" HeaderText="是否班长"
SortExpression="isking" />
<asp:TemplateField HeaderText="照片">
<ItemTemplate>
<table style="width:100%;">
<tr>
<td><a href='viewPhoto.aspx?photourl=<%#Eval("photo") %>' target="_blank">姓名:<%#Eval("sname") %></a></td>
</tr>
<tr>
<td class="style10">
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("photo") %>' Width="60px" Height="60px" ToolTip='<%#"这是:"+Eval("sname")%>'/>
</td>
</tr>
<tr>
<td>编号:<%#Eval("sid") %> 年龄:<%#Eval("age") %> </td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField HeaderText="删除" Text="删除" />
<asp:ButtonField CommandName="initialPassword" Text="初始化密码" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center"
VerticalAlign="Middle" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<div>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:studentConnectionString %>"
DeleteCommand="DELETE FROM [student] WHERE [sid] = @sid"
InsertCommand="INSERT INTO [student] ([sname], [classid], [sex], [age], [isking], [photo]) VALUES (@sname, @classid, @sex, @age, @isking, @photo)"
SelectCommand="SELECT [sid], [sname], [classid], [sex], [age], [isking], [photo] FROM [student]"
UpdateCommand="UPDATE [student] SET [sname] = @sname, [classid] = @classid, [sex] = @sex, [age] = @age, [isking] = @isking, [photo] = @photo WHERE [sid] = @sid">
<DeleteParameters>
<asp:Parameter Name="sid" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="sname" Type="String" />
<asp:Parameter Name="classid" Type="Int32" />
<asp:Parameter Name="sex" Type="String" />
<asp:Parameter Name="age" Type="Byte" />
<asp:Parameter Name="isking" Type="Boolean" />
<asp:Parameter Name="photo" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="sname" Type="String" />
<asp:Parameter Name="classid" Type="Int32" />
<asp:Parameter Name="sex" Type="String" />
<asp:Parameter Name="age" Type="Byte" />
<asp:Parameter Name="isking" Type="Boolean" />
<asp:Parameter Name="photo" Type="String" />
<asp:Parameter Name="sid" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _12_05GridView
{
public partial class GradView1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "initialPassword")//获取用户是点击了哪个按钮
{
//在这里写初始化的密码代码
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//可以在这个事件中处理已经完成的数据
//LinkButton lbtn = e.Row.Cells[6].Controls[0] as LinkButton;
if (e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
string sid=e.Row.Cells[0].Text;
HyperLink link = e.Row.Cells[1].Controls[0] as HyperLink;
LinkButton lbtn = e.Row.Cells[6].Controls[0] as LinkButton;
if (lbtn != null)
{
lbtn.Attributes.Add("onclick","return confirm('确定要删除编号为"+sid+"的"+link.Text+"吗?');");
}
}
}
}
2 使用模版列完成课上例子的实现,用一列显示 全部信息,同时完成修改的功能
<%@ Page Xlanguage="C#" AutoEventWireup="true" CodeBehind="GradView1.aspx.cs" Inherits="_12_05GridView.GradView1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style10
{
height: 17px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="sid" DataSourceID="SqlDataSource1" EmptyDataText="没有数据"
Font-Bold="True" Font-Size="Small" ForeColor="#333333" GridLines="None"
Height="40px" ShowFooter="True" Width="712px"
Xonrowcommand="GridView1_RowCommand" Xonrowdatabound="GridView1_RowDataBound"
style="margin-right: 81px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="sid" HeaderText="编号" InsertVisible="False"
ReadOnly="True" SortExpression="sid" />
<asp:HyperLinkField DataNavigateUrlFields="photo"
DataNavigateUrlFormatString="viewPhoto.aspx?photourl={0}" DataTextField="sname"
DataTextFormatString="点击查看{0}" HeaderText="姓名" Target="_blank"
NavigateUrl="~/viewPhoto.aspx" />
<asp:BoundField DataField="sex" HeaderText="性别" SortExpression="sex" />
<asp:BoundField DataField="age" HeaderText="年龄" SortExpression="age" />
<asp:CheckBoxField DataField="isking" HeaderText="是否班长"
SortExpression="isking" />
<asp:TemplateField HeaderText="照片">
<ItemTemplate>
<table style="width:100%;">
<tr>
<td><a href='viewPhoto.aspx?photourl=<%#Eval("photo") %>' target="_blank">姓名:<%#Eval("sname") %></a></td>
</tr>
<tr>
<td class="style10">
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("photo") %>' Width="60px" Height="60px" ToolTip='<%#"这是:"+Eval("sname")%>'/>
</td>
</tr>
<tr>
<td>编号:<%#Eval("sid") %> 年龄:<%#Eval("age") %> </td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField HeaderText="删除" Text="删除" />
<asp:ButtonField CommandName="initialPassword" Text="初始化密码" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center"
VerticalAlign="Middle" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<div>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:studentConnectionString %>"
DeleteCommand="DELETE FROM [student] WHERE [sid] = @sid"
InsertCommand="INSERT INTO [student] ([sname], [classid], [sex], [age], [isking], [photo]) VALUES (@sname, @classid, @sex, @age, @isking, @photo)"
SelectCommand="SELECT [sid], [sname], [classid], [sex], [age], [isking], [photo] FROM [student]"
UpdateCommand="UPDATE [student] SET [sname] = @sname, [classid] = @classid, [sex] = @sex, [age] = @age, [isking] = @isking, [photo] = @photo WHERE [sid] = @sid">
<DeleteParameters>
<asp:Parameter Name="sid" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="sname" Type="String" />
<asp:Parameter Name="classid" Type="Int32" />
<asp:Parameter Name="sex" Type="String" />
<asp:Parameter Name="age" Type="Byte" />
<asp:Parameter Name="isking" Type="Boolean" />
<asp:Parameter Name="photo" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="sname" Type="String" />
<asp:Parameter Name="classid" Type="Int32" />
<asp:Parameter Name="sex" Type="String" />
<asp:Parameter Name="age" Type="Byte" />
<asp:Parameter Name="isking" Type="Boolean" />
<asp:Parameter Name="photo" Type="String" />
<asp:Parameter Name="sid" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _12_05GridView
{
public partial class GradView1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "initialPassword")//获取用户是点击了哪个按钮
{
//在这里写初始化的密码代码
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//可以在这个事件中处理已经完成的数据
//LinkButton lbtn = e.Row.Cells[6].Controls[0] as LinkButton;
if (e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
string sid=e.Row.Cells[0].Text;
HyperLink link = e.Row.Cells[1].Controls[0] as HyperLink;
LinkButton lbtn = e.Row.Cells[6].Controls[0] as LinkButton;
if (lbtn != null)
{
lbtn.Attributes.Add("onclick","return confirm('确定要删除编号为"+sid+"的"+link.Text+"吗?');");
}
}
}
}
相关文章推荐
- 使用自定义列显示班级学生信息,要求能够进 行删除和修改,删除时给出提示:如 “ 确信要删 除 - 张三 - 吗? ” ,其中张三为当前行的姓名
- GridView 自定义列,删除时给出提示:如 “ 确信要删 除 - 张三 - 吗? ” ,其中张三为当前行的姓名
- GridView 自定义列,删除时给出提示:如 “ 确信要删 除 - 张三 - 吗? ” ,其中张三为当前行的姓名
- GridView 自定义列,删除时给出提示:如 “ 确信要删 除 - 张三 - 吗? ” ,其中张三为当前行的姓名
- GridView 自定义列,删除时给出提示:如 “ 确信要删 除 - 张三 - 吗? ” ,其中张三为当前行的姓名
- 制作一个表格,显示班级的学生信息,要求可以删除行和添加行
- 使用HashSet和TreeSet存储多个商品信息,遍历并输出;其中商品属性:编号,名称,单价,出版社;要求向其中添加多个相同的商品,验证集合中元素的唯一性。 提示:向HashSet中添加自定义
- c语言使用链表编写一个可以实现班级学生管理系统,增加,删除,修改学生信息
- 一个学生的信息是:姓名,学号,性别,年龄等信息,用一个链表,把这些学生信息连在一起, 给出一个age, 在些链表中删除学生年龄等于age的学生信息。
- 使用XmlDocument将dropdownlist中显示的书名的其它信息读入到相应的文本框中。添加 :删除按钮,修改并保存按钮 和 添加按钮。完成这些按钮所对应的功能(XmlDocument)
- 存储班长信息的学生类,将Stu类的数据成员的访问权限改为private,你的程序是否能完成要求的功能?如果不行,请修改程序。请不要修改给出的代码,只能修改自己写的代码。
- 学生信息是:姓名,学号,性别,年龄,用一个链表,把这些信息连在一起,给出一个age, 在些链表中删除学生年龄等于age的学生信息。
- [Unity3D]使用OnGUI函数显示状态栏并且使用触发器修改玩家当前信息
- 一个学生的信息是:姓名,学号,性别,年龄等信息,用一个链表,把这些学生信息连在一起, 给出一个age, 在 链表中删除学生年龄等于age的学生信息。
- javascript编程小练习--制作一个表格,动态增加删除显示班级的学生信息。
- 用C语言模拟实现一个通讯录,要求实现其添加、删除、修改、查找、显示和排序联系人信息的功能
- 给出n个学生的考试成绩表,每条记录由学号、姓名和分数和名次组成,设计算法完成下列操作: (1)设计一个显示对学生信息操作的菜单函数如下所示: *************************
- 一个学生的信息是:姓名,学号,性别,年龄等信息,用一个链表,把这些学生信息连在一起, 给出一个age, 在些链表中删除学生年龄等于age的学生信息。
- 在昨天作业的基础上添加 :删除按钮,修改并保存按钮 和 添加按钮。完成这些按钮所对应的功能/新建页面DataXML,使用GridView显示book.xm中的图书信息
- 字符串数组 输入3个字符串,要求按由小到大的字母顺序输出; 输入n个学生的姓名和学号到字符串数组中,在输入一个姓名,如果班级有该生则返回其信息,否则返回本班无此人