带复选框的Gridview范围选择 [英] Gridview with Checkboxes range select
问题描述
大家
我有一个gridview,第一列是复选框,gridview的页面大小是50.
现在,我想给出在gridview中选择复选框的范围.例如,如果我给出1-5意味着需要在gridview中选中1至5行复选框.Grid也具有分页功能.在每页中,范围只能在1到50之间.有谁能够帮助我.这很紧急.预先感谢.
这里的代码:
Hi, all
I have a gridview, the first column is checkbox, the page size of gridview is 50.
Now i want to give the range for selecting check boxes in the gridview. Ex.If i give 1-5 means that 1 to 5 rows checkboxes need to select in the gridview.Grid have the paging also. In every page the range must be in 1 to 50 only. Can any body help me. Its urgent. Thank in advance.
Here the code:
<asp:GridView ID="grvRecords" runat ="server" AutoGenerateColumns="false" Font-Bold="True"
Font-Names="Trebuchet MS" Font-Size="10px" AllowPaging="True"
onpageindexchanging="grvRecords_PageIndexChanging" PageSize="50"
Font-Underline="False" AllowSorting="True" onsorting="grvRecords_Sorting" >
<columns>
<asp:TemplateField >
<HeaderTemplate >
<input id="chkAllItems" type="checkbox" onclick="CheckAllDataGridCheckBoxes('chkItemChecked',document.forms[0].chkAllItems.checked)" value="Check">
</HeaderTemplate>
<itemtemplate>
<asp:CheckBox id="chkBulk" runat="server" Width="30px" AutoPostBack="False">
</itemtemplate>
脚本是:(firstno,lastno是范围)
and the Script is:(firstno, lastno is the range)
var grid1 = document.getElementById("<%= grvRecords.ClientID %>");
if (grid1.rows.length > 0) {
for (var i = firstno - 1; i < secondno; i++) {
var cell = grid1.rows[i].cells[0];
for (var j = 0; j < cell.childNodes.length; j++) {
if (cell.childNodes[j].type == "checkbox" && cell.childNodes[j].name=="chkBulk" ) {
cell.childNodes[j].checked = true;
}
}
}
}
上面的代码没有输出.
The above code is not getting output.
推荐答案
这只是您的情况的一个示例:-
This is just an example for your scenario:-
protected void Page_Load(object sender, EventArgs e)
{
ArrayList arr = new ArrayList();
arr.Add("1");
arr.Add("2");
arr.Add("3");
arr.Add("4");
arr.Add("5");
arr.Add("6");
arr.Add("7");
GridView1.DataSource = arr;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chk = (CheckBox)e.Row.FindControl("CheckBox1");
if (e.Row.RowIndex <= 4)
{
chk.Checked=true;
}
}
}
这篇关于带复选框的Gridview范围选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!