asp.net(C#)中的gridview中怎样加入带选择方框的列?如图。解决了,在加分
5个回答
展开全部
提出整个代码裤耐培 希望对你有用,下面是自己重写了下Gridview 你可以不用在意
<L:SunGridView ID="GridViewShow" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CssClass="datalist" PageSize="12" SortIcoArrowPath="../">
<PagerSettings Mode="NumericFirstLast" />
<Columns>
<asp:TemplateField meta:resourcekey="DetilData" ItemStyle-Width="5%">
<itemtemplate>
<input runat="server" value='<亩链%# Eval("ID") %>' id="ChkDataID" type="checkbox" class="checkbox"
onmouseover="this.mouse='over'" onmouseout="this.mouse='out'" mouse="out" />
</itemtemplate>
<itemstyle horizontalalign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" ItemStyle-Width="5%" /胡唯>
<asp:BoundField HeaderText="用户组代号" DataField="ShortName" SortExpression="ShortName" ItemStyle-Width="15%" />
<asp:BoundField HeaderText="用户组名称" DataField="Name" SortExpression="Name" ItemStyle-Width="30%" />
<asp:BoundField HeaderText="创建人" DataField="CreateBy" SortExpression="CreateBy" ItemStyle-Width="20%" />
<asp:BoundField HeaderText="创建时间" DataField="CTime" SortExpression="CTime" ItemStyle-Width="20%" />
<asp:TemplateField meta:resourcekey="DetilData" HeaderText="状态" ItemStyle-Width="5%">
<itemtemplate>
<asp:Label ID="lblDelState" runat="server" Text='<%# FormatDelState(DataBinder.Eval(Container, "DataItem(Status)","{0}")) %>'> id="lblDelState"></asp:Label>
</itemtemplate>
<itemstyle horizontalalign="Center" />
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="category" />
</L:SunGridView>
加入隐藏域 用来接收 选中的行的ID号
<asp:HiddenField ID="CheckedDataIDS" runat="server" Value="0" />
下面是JS代码:
function CheckAll() {
var InputList = document.getElementsByTagName("input");
var InputAll = document.getElementById("ChkSelectAll");
for(var j = 0 ; j < InputList.length ; j++){
if(InputList[j].type == "checkbox" && InputList[j].id.indexOf('ChkDataID') != -1){
InputList[j].checked = InputAll.checked == true ? true : false;
if(InputList[j].checked == true){
InputList[j].parentNode.parentNode.style.backgroundColor='#F7F7F7';
InputList[j].parentNode.parentNode.IsSelected = "1";
}else{
InputList[j].parentNode.parentNode.style.backgroundColor='#ffffff';
InputList[j].parentNode.parentNode.IsSelected = "0";
}
}
}
}
调用方法:
<input id="ChkSelectAll" onclick="CheckAll()" type="checkbox" class="checkbox" />
<asp:Label ID="lblSelectAll" runat="server" Text="全选" />
希望对你有用
<L:SunGridView ID="GridViewShow" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CssClass="datalist" PageSize="12" SortIcoArrowPath="../">
<PagerSettings Mode="NumericFirstLast" />
<Columns>
<asp:TemplateField meta:resourcekey="DetilData" ItemStyle-Width="5%">
<itemtemplate>
<input runat="server" value='<亩链%# Eval("ID") %>' id="ChkDataID" type="checkbox" class="checkbox"
onmouseover="this.mouse='over'" onmouseout="this.mouse='out'" mouse="out" />
</itemtemplate>
<itemstyle horizontalalign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" ItemStyle-Width="5%" /胡唯>
<asp:BoundField HeaderText="用户组代号" DataField="ShortName" SortExpression="ShortName" ItemStyle-Width="15%" />
<asp:BoundField HeaderText="用户组名称" DataField="Name" SortExpression="Name" ItemStyle-Width="30%" />
<asp:BoundField HeaderText="创建人" DataField="CreateBy" SortExpression="CreateBy" ItemStyle-Width="20%" />
<asp:BoundField HeaderText="创建时间" DataField="CTime" SortExpression="CTime" ItemStyle-Width="20%" />
<asp:TemplateField meta:resourcekey="DetilData" HeaderText="状态" ItemStyle-Width="5%">
<itemtemplate>
<asp:Label ID="lblDelState" runat="server" Text='<%# FormatDelState(DataBinder.Eval(Container, "DataItem(Status)","{0}")) %>'> id="lblDelState"></asp:Label>
</itemtemplate>
<itemstyle horizontalalign="Center" />
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="category" />
</L:SunGridView>
加入隐藏域 用来接收 选中的行的ID号
<asp:HiddenField ID="CheckedDataIDS" runat="server" Value="0" />
下面是JS代码:
function CheckAll() {
var InputList = document.getElementsByTagName("input");
var InputAll = document.getElementById("ChkSelectAll");
for(var j = 0 ; j < InputList.length ; j++){
if(InputList[j].type == "checkbox" && InputList[j].id.indexOf('ChkDataID') != -1){
InputList[j].checked = InputAll.checked == true ? true : false;
if(InputList[j].checked == true){
InputList[j].parentNode.parentNode.style.backgroundColor='#F7F7F7';
InputList[j].parentNode.parentNode.IsSelected = "1";
}else{
InputList[j].parentNode.parentNode.style.backgroundColor='#ffffff';
InputList[j].parentNode.parentNode.IsSelected = "0";
}
}
}
}
调用方法:
<input id="ChkSelectAll" onclick="CheckAll()" type="checkbox" class="checkbox" />
<asp:Label ID="lblSelectAll" runat="server" Text="全选" />
希望对你有用
展开全部
gridview加个面板列岩雀就可以了,怎么实现CheckBox功能才是关键吧
<粗枣早asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="岩辩CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<粗枣早asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="岩辩CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<asp:GridView ID="GridView1" runat="橡轮server">
<Columns>
<asp:TemplateField HeaderText="TemplateField" FooterText="qq">
<HeaderTemplate>
<asp:CheckBox ID="CheckBox4" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="做核CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这样就ok, 给纯如掘我分哦
<Columns>
<asp:TemplateField HeaderText="TemplateField" FooterText="qq">
<HeaderTemplate>
<asp:CheckBox ID="CheckBox4" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="做核CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这样就ok, 给纯如掘我分哦
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
模版列里面放复选框
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询