DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
newColumn.HeaderText = "选择";
dataGridView.Columns.Insert(0, newColumn);
dataGridView.MultiSelect = true;
newColumn.InheritedStyle.Alignment = DataGridViewContentAlignment.TopCenter;
newColumn.Width = 35;我用上面的方法给DataGridView添加了一列CheckBox,也设置了MultiSelect=True,为什么还是不能多选呢?望大虾们指点一下.谢谢.
就可以了
选了个checkbox,循环判断下checkbox的值为true,不就得到多条记录了吗
我的做法是:不要前面的勾,直接按ctrl进行多选,然后把selected的项全部输出就得到了所要的结果
我上次是xml文档的问题
你用什么表示来表示的true false
<GridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" PageSizes="20" VirtualMode="false" Width="0">
<Columns DataPropertyName="LogContent" DataPropertyType="System.String" DefaultDraw="false" FormatString="" HeaderText="日志内容" IsComboBox="false" IsFill="false" IsKey="false" Ordinal="4" ReadOnly="true" Visible="true" Width="0" />
<Columns DataPropertyName="Operator" DataPropertyType="System.Guid" DefaultDraw="false" FormatString="" HeaderText="操作员" IsComboBox="true" IsFill="false" IsKey="false" Ordinal="1" ReadOnly="true" Visible="true" Width="0" ValueMember="ID" DisplayMember="NameCn" />
<Columns DataPropertyName="OperateTime" DataPropertyType="System.DateTime" DefaultDraw="false" FormatString="yyyy-MM-dd" HeaderText="操作时间" IsComboBox="false" IsFill="false" IsKey="false" Ordinal="5" ReadOnly="true" Visible="true" Width="0" />
<Columns DataPropertyName="LogTypeID" DataPropertyType="JYWL.Sys.Share.SysLogType" DefaultDraw="false" FormatString="" HeaderText="操作类型" IsComboBox="false" IsFill="false" IsKey="false" Ordinal="2" ReadOnly="true" Visible="true" Width="0" />
<Columns DataPropertyName="KeyWords" DataPropertyType="System.String" DefaultDraw="false" FormatString="" HeaderText="关键字" IsComboBox="false" IsFill="false" IsKey="false" Ordinal="3" ReadOnly="true" Visible="true" Width="0" />
<Columns DataPropertyName="LogNO" DataPropertyType="System.Guid" DefaultDraw="false" FormatString="" HeaderText="序号" IsComboBox="false" IsFill="false" IsKey="true" Ordinal="0" ReadOnly="false" Visible="false" Width="0" />
</GridConfig>
这是绑定的xml文档.是不是这里面的问题?大哥些帮帮忙
谷歌和百度都找完了.没有答案啊.急死了
if(grid==null)
return false;
var gi=grid.getElementsByTagName("input")
for(var i=0;i<gi.length;i++)
{
if(gi[i].checked){
flag=true;
}
}
我上次是用的1,0
你用true,false看看
这样还是不行 DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
newColumn.HeaderText = "选择";
dataGridView.Columns.Insert(0, newColumn);//添加CheckBox
newColumn.InheritedStyle.Alignment = DataGridViewContentAlignment.TopCenter;
newColumn.Width = 35;
newColumn.TrueValue = 1;
newColumn.FalseValue = 0;
dataGridView.MultiSelect = true;//设置可以选中多行
<script type="text/javascript">
function CheckboxChoose(choosed)
{
var elementOnes=document.form1.elements;
var boolAll=true;
var controlAll;
for(var i=0;i<elementOnes.length;i++)
{
if(choosed.id.indexOf('CheckAll')!=-1)
{
elementOnes[i].checked=choosed.checked;
controlAll=elementOnes[i];
}
else if(choosed.id.indexOf('DeleteThis')!=-1)
{
if(elementOnes[i].id.indexOf('CheckAll')!=-1)
{
controlAll=elementOnes[i];
controlAll.checked=true;
}
if(elementOnes[i].checked==false)
{
boolAll=false;
}
}
}
controlAll.checked=boolAll;
}
</script>
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="width: 90px">
申请编号:</td>
<td style="width: 110px">
<asp:TextBox ID="txtId" runat="server"></asp:TextBox></td>
<td style="width: 70px">
申请人:</td>
<td style="width: 70px">
<asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
<td style="width: 70px">
<asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="查询" /></td>
<td style="width: 55px">
<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="添加" /></td>
<td style="width: 55px">
<asp:Button ID="btnUpdate" runat="server" Text="修改" OnClick="btnUpdate_Click" /></td>
<td colspan="4" style="width: 51px">
<asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" Text="删除"/></td>
</tr>
</table>
<asp:GridView ID="gridBackNoteList" runat="server" AutoGenerateColumns="False" DataKeyNames="ASSETID"
Width="701px">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckAll" runat="server" onclick="return CheckboxChoose(this); " />
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<input id="DeleteThis" name="DeleteThis" type="checkbox" value='<%# Eval("ASSETID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="ASSETID" DataNavigateUrlFormatString="Default2.aspx?id={0}"
DataTextField="ASSETID" HeaderText="申请人编号:">
<ItemStyle HorizontalAlign="Center" />
</asp:HyperLinkField>
<asp:BoundField DataField="ASSETNAME" FooterText="ASSETNAME" HeaderText="申请人:">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<EmptyDataTemplate>
<thead>
<th>
申请人编号</th>
<th>
申请人</th>
</thead>
<tr class="data">
<td align="center" colspan="8">
暂无数据</td>
</tr>
</EmptyDataTemplate>
</asp:GridView>
</div>
</form>
</body>
</html>
兄弟,如果是B/S模式的就没这么麻烦了,一段js的代码就搞定了.关键现在是C/S模式下的
而且绑定的是xml.不过还是谢谢你
谁能解决.另外开贴送100分
你用的是true,false,
我以前用的是1,0
newColumn.HeaderText = "选择";
newColumn.InheritedStyle.Alignment = DataGridViewContentAlignment.TopCenter;
newColumn.Width = 35;
newColumn.TrueValue = "true";
newColumn.FalseValue = "false";
newColumn.DataPropertyName = "IsKey";
this.dataGridView1.Columns.Insert(0, newColumn); DataSet ds = new DataSet();
ds.ReadXml(@"D:\Windows Project File\checkBoxDemo\checkBoxDemo\TestXMLFile.xml");
this.dataGridView1.DataSource = ds.Tables["Columns"];运行结果ok
试试把你的DataGridView删掉,重新放一个,(怀疑你是不是修改了哪个属性,导致冲突)