......
//设置选中产品值
function SetSelProductID() {
var selectCount = 0;
var productID = "";
var productType = "";
var productName = "";
var lblProductName = document.getElementById("lblSelProductName");
var hidProductID = document.getElementById("hidProductID");
var inputs = document.getElementById("<%=GridView1.ClientID%>").getElementsByTagName("input");
lblProductName.innerText = "";
hidProductID.value = "";
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox" && inputs[i].checked) {
productID = inputs[i].parentElement.parentElement.lastChild.innerText;
productName = inputs[i].parentElement.parentElement.childNodes[2].innerText;
productType = inputs[i].parentElement.parentElement.childNodes[6].innerText;
if (lblProductName.innerText == "") {
lblProductName.innerText = productName;
hidProductID.value = productID + "," + productType;
} else {
lblProductName.innerText = lblProductName.innerText + ";" + productName;
hidProductID.value = hidProductID.value + ";" + productID + "," + productType;
}
}
}
}
......
<asp:GridView ID="GridView1" runat="server" AllowPagerable="False"
AllowChangeCellWidth="True" AutoGenerateColumns="False"
CellPadding="0" DataKeyNames="ID" GridLines="None"
CssClass="gridviewStyle" JumpButtonHeight="25px" JumpButtonWidth="25px"
onrowdatabound="GridView1_RowDataBound" >
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemStyle CssClass="gridview_itemStyle" Width="40px" HorizontalAlign="Center"/>
<HeaderStyle CssClass="gridview_headerStyle" Width="40px"/>
<ItemTemplate>
<input id="Checkbox1" type="checkbox" onclick ="SetSelProductID();" />
</ItemTemplate>
</asp:TemplateField>
......
<asp:TemplateField HeaderText="产品类别2">
<ItemStyle CssClass="gridview_hiddenItemStyle" HorizontalAlign="left" Width="0px" />
<HeaderStyle CssClass="gridview_hiddenItemStyle" Width="0px" />
<ItemTemplate>
<asp:Label ID="lblType2" runat="server" Text='<%# Eval("ProductCategory") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ProductID" HeaderText="产品ID">
<ItemStyle CssClass="gridview_hiddenItemStyle" HorizontalAlign="left" Width="0px" />
<HeaderStyle CssClass="gridview_hiddenItemStyle" Width="0px" />
</asp:BoundField>
</Columns>
<RowStyle CssClass="gridview_rowStyle" />
<AlternatingRowStyle CssClass="gridview_alternatingRowStyle" />
<EmptyDataTemplate>
<table class="itemtable" cellspacing="1" cellpadding="2" border="0">
<tbody>
<tr class="toplinebg">
<td width="40px" height="20">选择</td>
<td width="60px">序号</td>
<td width="100px">产品编号</td>
<td width="180px">产品名称</td>
<td width="60px">产品状态</td>
<td width="60px">所属分公司</td>
<td width="100px">产品类别</td>
</tr>
<tr >
<td height="20" class="gridview_itemStyle2" colspan="7">暂无信息</td>
</tr>
</tbody>
</table>
</EmptyDataTemplate>
</asp:GridView>
css里的样式:
.gridview_hiddenItemStyle
{
display:none;
}