本文介绍了基于Gridview行的CheckBox选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我的GridView看起来像这样..
Hi everybody,
My GridView is look like this..
col1 col2 col3
1 A 1.2
2 B 3.4
C 2.3
3 A 2
这里col1是PK列,现在我正在为gridview的每一行做checkBox选择。
javascript:
Here col1 is PK column now i''m doing checkBox selection for each and every row of gridview.
javascript:
function CheckAll(oCheckbox)
{
var gdDocument = document.getElementById("<%=gdDocument.ClientID %>");
for (i = 1; i < gdDocument.rows.length; i++) {
gdDocument.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
}
}
代码落后:
code behind:
<asp:TemplateField>
<HeaderTemplate>
<input id="chkSelect" type="checkbox" onclick="CheckAll(this)" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
此代码用于gridview所有行选择。但我希望基于PK列我想显示复选框。
ex:
in row 3没有col1的记录。所以,我不想在那一行显示复选框。
如何做到这一点任何人都可以帮助我.. 。
this code for gridview all rows selection. But i want based upon PK column i want to display the checkBox.
ex:
in row 3 there is no record for col1. so, i don''t want to display checkbox in that row .
How to do this can any one help me...
推荐答案
for (int i = 0; i < GridView1.Rows.Count; i++)
{
if (GridView1.Rows[i].Cells[0].Text == string.Empty)
{
CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
chk.Visible = false;
}
}
享受编码......
玩得开心:)
Enjoy coding ...
have fun :)
这篇关于基于Gridview行的CheckBox选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!