关于VS2005中GridView的自定义分页单选、多选、排序、 自增列的简单应用。
多选时只有全部选中时“多选”才选中。
图片效果
简单示例代码如下fenpage.aspx的代码
.cs" Inherits="gridview_fenpage"%>
<!DOCTYPE html PUBLIC"-//W3C//DTDXHTML 1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional .dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
>
//判断多选是否与选中项没有选中的返回false
)
{
)
{
++)
{
)
{
;
}
}
}
{
)
{
;
}
}
alert("请选择后再操作 ");
;
}
//鼠标经过改变行的颜色
)
{
;
;
}
)
{
{
;}
;
;
";
}
//
//多选的全选与取消
)
{
)
{
++){
;}
}
;
}
//
//只有全部选中时“全选”选中
()
{
;
;
)
{
++){
)
;
;
}
}
{
)
;
;
}
)
;
;
}
//
>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cel lpadding="0" cel lspacing="0" border="0"width="80%" style="font-size: 11px">
<tr>
<td al ign="center">
<asp:GridView ID="GridView1" runat="server"Width="100%"Cel lPadding="4" ForeColor="#333333"
AutoGenerateColumns="False"Al lowPaging="True" PageSize="12" Borde rColor="Si lver"
BorderStyle="Sol id" BorderWidth="1px"OnRowDataBound="GridView1_RowDataBound"
ShowFooter="True" EmptyDataText="没有数据记录 "Al low
Sorting="True"OnSorting="GridView1_Sorting">
<Columns>
<asp:BoundField HeaderText="编号"DataField="id"Visible="False"/>
<asp:TemplateField HeaderText="< input type='checkbox' id='chk' name='chk'oncl ick='checkJs(this.checked); ' />全选" FooterText="全选">
<ItemTemplate>
<input type="checkbox" id="checkboxname" name="checkboxname"value='<%# DataBinder.Eval(Container.DataItem, "id")%>' oncl ick='SingleCheckJs(); ' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="单选" FooterText="单选">
<ItemTemplate>
<input type="radio" id="RadioName" name="RadioName"value='<%#Eval("id")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="自增列" FooterText="自增列">
<ItemTemplate>
()%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="姓名" FooterText="姓名"DataField="name"SortExpression="name"/>
<asp:BoundField HeaderText="身份证号" FooterText="身份证号"DataField="card"SortExpression="card"/>
<asp:BoundField HeaderText="价格" FooterText="价格"DataField="price"DataFormatString="{0:#,##0.00}"
HtmlEncode="False"SortExpression="price"/>
<asp:BoundField HeaderText="数字" FooterText="数字"DataField="price"DataFormatString="{0:0.00}"
HtmlEncode="False"SortExpression="price"/>
<asp:BoundField HeaderText="建立时间" FooterText="建立时间"DataField="c reatedate"DataFormatString="{0:yyyy年M M月dd日 hh时mm分ss秒}"
HtmlEncode="False"SortExpression="createdate"/>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333"/>
<EditRowStyle BackColor="#999999"/>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"/>
<PagerStyle BackColor="#284775" ForeColor="White"HorizontalAl ign="Center"/>
<AlternatingRowStyle BackColor="White" ForeColor="#284775"/>
<PagerSettings Visible="False"/>
<FooterStyle Font-Bold="True"/>
<HeaderStyle Font-Bold="False" Font-Ital ic="False"/>
</asp:GridView>
</td>
</tr>
<tr>
<td al ign="center" style="height: 25px">
<asp:LinkButton ID="btnFirst"CommandArgument="first"OnCl ick="PagerButtonCl ick"runat="server">首页</asp:LinkButton>
<asp:LinkButton ID="btnPrev"CommandArgument="prev"OnCl ick="PagerButtonCl ick" runat="server">上一页</asp:LinkButton>
<asp:LinkButton ID="btnNext"CommandArgument="next"OnCl ick="PagerButtonCl ick" runat="server">下一页</asp:LinkButton>
<asp:LinkButton ID="btnLast"CommandArgument="last"OnClick="PagerButtonCl ick" runat="server">尾页</asp:LinkButton>
<asp:Label ID="LblCurrentIndex" runat="server"></asp:Label>
<asp:Label ID="LblPageCount" runat="server"></asp:Label>
<asp:Label ID="LblRecordCount" runat="server"></asp:Label></td>
</tr>
<tr>
<td>
<asp:Button ID="Button2" runat="server"Text="checkbox得到选择的行"OnCl ick="Button2_Cl ick">
</asp:Button>
<asp:Button ID="Button1" runat="server"Text="radio得到选择的行"OnCl ick="Button1_Cl ick"></asp:Button>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>fenpage.aspx.cs的代码using System;using System.Data;
using System.Configuration;using System.Col lections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlCl ient;publ ic partial class gridview_fenpage : System.Web.UI.Page
{
)
{
); ";
("");
}
)
{
].ConnectionString;
;();
{
;
();
);
da.Fi l l(ds, "test01");
();
;
();
() +"页";
()+"页";()+"条";
)
{
;
;
;
;
;
;
;
}
)
{
;
;
;
;
}
mansora怎么样?mansora是一家国人商家,主要提供沪韩IEPL、沪日IEPL、深港IEPL等专线VPS。现在新推出了英国CN2 KVM VPS,线路为AS4809 AS9929,可解锁 Netflix,并有永久8折优惠。英国CN2 VPS,$18.2/月/1GB内存/10GB SSD空间/1TB流量/100Mbps端口/KVM,有需要的可以关注一下。点击进入:mansora官方网站地址m...
现在宝塔面板真的是越来越过分了,删除文件、删除数据库、删除站点等操作都需要做计算题!我今天升级到7.7版本,发现删除数据库竟然还加了几秒的延时等待,也无法跳过!宝塔的老板该不会是小学数学老师吧,那么喜欢让我们做计算题!因此我写了个js用于去除各种计算题以及延时等待,同时还去除了软件列表页面的bt企业版广告。只需要执行以下命令即可一键完成!复制以下命令在SSH界面执行:Layout_file="/w...
零途云是一家香港公司,主要产品香港cn2 gia线路、美国Cera线路云主机,美国CERA高防服务器,日本CN2直连服务器;同时提供香港多ip站群云服务器。即日起,购买香港/美国/日本云服务器享受9折优惠,新用户有优惠码:LINGTUYUN,使用即可打折。目前,零途云还推出性价比非常高香港多ip站群云服务器,有需要的,可以关注一下。零途云优惠码:优惠码:LINGTUYUN (新用户优惠,享受9折优...