3个回答
展开全部
<Columns>
<asp:TemplateColumn HeaderText="Checked" HeaderStyle-Width="30">
<HeaderTemplate>
<input id="chkAllInBox" type="checkbox" onclick="selectAll('chkAllInBox','<%# this.grdList.ClientID %>')" />
</HeaderTemplate>
<ItemTemplate>
<input type="checkbox" id="chids" value='<%# DataBinder.Eval(Container, "DataItem.ID") %>'
runat="server" name="chids" />
</ItemTemplate>
<HeaderStyle Width="30px"></HeaderStyle>
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" HorizontalAlign="Center" />
</asp:TemplateColumn>
<asp:BoundColumn DataField="ID" SortExpression="ID" HeaderText="id" Visible="false">
</asp:BoundColumn>
<asp:BoundColumn DataField="EventCount" SortExpression="EventCount" HeaderText='数量'></asp:BoundColumn>
<asp:BoundColumn DataField="DomainName" HeaderText="类型" SortExpression="DomainName">
</asp:BoundColumn>
<asp:BoundColumn DataField="CalItemName" SortExpression="CalItemName" HeaderText="计算项">
</asp:BoundColumn>
<asp:BoundColumn DataField="CalUnitName" SortExpression="CalUnitName" HeaderText="地区或单位">
</asp:BoundColumn>
<asp:BoundColumn DataField="EventDesc" SortExpression="EventDesc" HeaderText="事件描述">
</asp:BoundColumn>
<asp:BoundColumn DataField="Month" SortExpression="Month" HeaderText="上报月份"></asp:BoundColumn>
<asp:BoundColumn DataField="DraftWriter" SortExpression="DraftWriter" HeaderText="填写人">
</asp:BoundColumn>
<asp:BoundColumn DataField="DraftWriteTime" SortExpression="DraftWriteTime" HeaderText="填写时间"
DataFormatString='{0:d}'></asp:BoundColumn>
<%--<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label ID="lblPar1Name" runat="server"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPar1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label ID="lblPar2Name" runat="server"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPar2" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label ID="lblPar3Name" runat="server"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPar3" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>--%>
<asp:BoundColumn DataField="Par1" SortExpression="Par1" HeaderText="批次" Visible="False">
</asp:BoundColumn>
<asp:BoundColumn DataField="Par2" SortExpression="Par2" HeaderText="Par2" Visible="False">
</asp:BoundColumn>
<asp:BoundColumn DataField="Par3" SortExpression="Par3" HeaderText="Par3" Visible="False">
</asp:BoundColumn>
<asp:TemplateColumn HeaderStyle-Width="40" ItemStyle-HorizontalAlign="Center" HeaderText="编辑">
<ItemTemplate>
<asp:HyperLink ID="hlkEditInfo" runat="server" ImageUrl="~/images/edit.gif" NavigateUrl='<%# EditUrl("ItemId",DataBinder.Eval(Container, "DataItem.ID").ToString(),"Edit") %>'></asp:HyperLink>
</ItemTemplate>
<HeaderStyle Width="40px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderStyle-Width="40" ItemStyle-HorizontalAlign="Center" HeaderText="删除">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbnDelInfo" CommandName="CommandDelete" BorderStyle="None">
<asp:Image runat="server" ID="imgDelete" BorderStyle="None" ImageUrl="~\images\button_delete.gif"
ImageAlign="AbsMiddle"></asp:Image>
</asp:LinkButton>
</ItemTemplate>
<HeaderStyle Width="40px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateColumn>
</Columns>
<script language="javascript">
//全选
function selectAll(SourceID, ControlID) {
var sourceBox = document.getElementById(SourceID);
var theBox = document.all(ControlID);
elm = theBox.getElementsByTagName('Input');
for (i = 0; i < elm.length; i++) {
if (elm[i].type == "checkbox") {
elm[i].checked = sourceBox.checked;
}
}
}
//选择删除检测
function CheckNULL(ControlID) {
var isNULL = false;
var theBox = document.all(ControlID);
elm = theBox.getElementsByTagName('Input');
for (var i = 0; i < elm.length; i++) {
var e = elm[i];
if (e.type == "checkbox" && e.checked == true && e.id != "chkAllInBox") {
isNULL = true;
}
}
if (isNULL == false) {
alert('请选择删除项!');
return false;
}
else {
return confirm('确定要删除信息?');
}
}
</script>
<asp:TemplateColumn HeaderText="Checked" HeaderStyle-Width="30">
<HeaderTemplate>
<input id="chkAllInBox" type="checkbox" onclick="selectAll('chkAllInBox','<%# this.grdList.ClientID %>')" />
</HeaderTemplate>
<ItemTemplate>
<input type="checkbox" id="chids" value='<%# DataBinder.Eval(Container, "DataItem.ID") %>'
runat="server" name="chids" />
</ItemTemplate>
<HeaderStyle Width="30px"></HeaderStyle>
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" HorizontalAlign="Center" />
</asp:TemplateColumn>
<asp:BoundColumn DataField="ID" SortExpression="ID" HeaderText="id" Visible="false">
</asp:BoundColumn>
<asp:BoundColumn DataField="EventCount" SortExpression="EventCount" HeaderText='数量'></asp:BoundColumn>
<asp:BoundColumn DataField="DomainName" HeaderText="类型" SortExpression="DomainName">
</asp:BoundColumn>
<asp:BoundColumn DataField="CalItemName" SortExpression="CalItemName" HeaderText="计算项">
</asp:BoundColumn>
<asp:BoundColumn DataField="CalUnitName" SortExpression="CalUnitName" HeaderText="地区或单位">
</asp:BoundColumn>
<asp:BoundColumn DataField="EventDesc" SortExpression="EventDesc" HeaderText="事件描述">
</asp:BoundColumn>
<asp:BoundColumn DataField="Month" SortExpression="Month" HeaderText="上报月份"></asp:BoundColumn>
<asp:BoundColumn DataField="DraftWriter" SortExpression="DraftWriter" HeaderText="填写人">
</asp:BoundColumn>
<asp:BoundColumn DataField="DraftWriteTime" SortExpression="DraftWriteTime" HeaderText="填写时间"
DataFormatString='{0:d}'></asp:BoundColumn>
<%--<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label ID="lblPar1Name" runat="server"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPar1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label ID="lblPar2Name" runat="server"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPar2" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Label ID="lblPar3Name" runat="server"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPar3" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>--%>
<asp:BoundColumn DataField="Par1" SortExpression="Par1" HeaderText="批次" Visible="False">
</asp:BoundColumn>
<asp:BoundColumn DataField="Par2" SortExpression="Par2" HeaderText="Par2" Visible="False">
</asp:BoundColumn>
<asp:BoundColumn DataField="Par3" SortExpression="Par3" HeaderText="Par3" Visible="False">
</asp:BoundColumn>
<asp:TemplateColumn HeaderStyle-Width="40" ItemStyle-HorizontalAlign="Center" HeaderText="编辑">
<ItemTemplate>
<asp:HyperLink ID="hlkEditInfo" runat="server" ImageUrl="~/images/edit.gif" NavigateUrl='<%# EditUrl("ItemId",DataBinder.Eval(Container, "DataItem.ID").ToString(),"Edit") %>'></asp:HyperLink>
</ItemTemplate>
<HeaderStyle Width="40px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderStyle-Width="40" ItemStyle-HorizontalAlign="Center" HeaderText="删除">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbnDelInfo" CommandName="CommandDelete" BorderStyle="None">
<asp:Image runat="server" ID="imgDelete" BorderStyle="None" ImageUrl="~\images\button_delete.gif"
ImageAlign="AbsMiddle"></asp:Image>
</asp:LinkButton>
</ItemTemplate>
<HeaderStyle Width="40px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateColumn>
</Columns>
<script language="javascript">
//全选
function selectAll(SourceID, ControlID) {
var sourceBox = document.getElementById(SourceID);
var theBox = document.all(ControlID);
elm = theBox.getElementsByTagName('Input');
for (i = 0; i < elm.length; i++) {
if (elm[i].type == "checkbox") {
elm[i].checked = sourceBox.checked;
}
}
}
//选择删除检测
function CheckNULL(ControlID) {
var isNULL = false;
var theBox = document.all(ControlID);
elm = theBox.getElementsByTagName('Input');
for (var i = 0; i < elm.length; i++) {
var e = elm[i];
if (e.type == "checkbox" && e.checked == true && e.id != "chkAllInBox") {
isNULL = true;
}
}
if (isNULL == false) {
alert('请选择删除项!');
return false;
}
else {
return confirm('确定要删除信息?');
}
}
</script>
展开全部
checkbox控件。
方法1、为checkbox控件增加客户端点击事件,用JSON对象保存选中项目,在其他按钮提交的时候将该JSON对象转换写入LIST<T>集合中。优点:不需要每次都提交刷新页面。
方法2、将该checkbox设置:AutoPostBack=true。到后台代码检测点击的是哪一行,再进行你的LIST泛型对象的增加删除逻辑。
方法1、为checkbox控件增加客户端点击事件,用JSON对象保存选中项目,在其他按钮提交的时候将该JSON对象转换写入LIST<T>集合中。优点:不需要每次都提交刷新页面。
方法2、将该checkbox设置:AutoPostBack=true。到后台代码检测点击的是哪一行,再进行你的LIST泛型对象的增加删除逻辑。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
将你要显示成checkbox的column type直接改成DataGridViewCheckBoxColumn即可。
也可以在插入新column时可以直接设置。
也可以在插入新column时可以直接设置。
追问
我是从数据库直接获取一张表绑定到DataGridView中,如何把整张表都设置成具有复选框功能?
追答
column的类型是不能被你以编程的形式动态的改变的。强制改变会抛出wrong type异常
你应该在导入数据的时候判断行列,然后建立CheckBoxColumn
---给你提供一种强制改变所有cell类型的方法---
for (int i = 0; i < dataGridView1.RowCount; i++)
{
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
dataGridView1.Rows[i].Cells[j] = new DataGridViewCheckBoxCell();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询