我有gridview with checkbox作为第一列,我试图使用附加到下面提到的复选框的javascript函数获取所选复选框的完整行值...
我尝试了不同的方法,但卡在中间,这就是我再次在这里发布的原因..
但有些我怎么没有进入for循环,我不知道我在这个代码中得到错误..
Javascript功能
function checkForVirtual(){
var GridView = document.getElementById('<%=gvPRCertInfo.ClientID %>');
if (GridView.rows.length > 0) {
alert('check');
for (Row = 1; Row < GridView.rows.length; Row++) {
alert("check 2 times");
if (GridView.rows[Row].cell[1].type == "checkbox") {
/// not getting into this
/// alert is not firing even if the checkbox is there
alert('inside');
if (GridView.rows[Row].cell[0].childNodes[0].checked) {
alert('checked');
var type = GridView.rows[Row].cell[3].childNodes[0].val();
alert(type);
}
}
}
}
}
这是我的网格视图
<asp:GridView ID="gvPRCertInfo" runat="server" AutoGenerateColumns="False" GridLines="None"
OnRowDataBound="gvPRCertInfo_RowDataBound"
CssClass="data responsive">
<Columns>
<asp:TemplateField HeaderText="Select" SortExpression="">
<HeaderTemplate>
<asp:CheckBox ID="chkboxSelectAll" runat="server" AutoPostBack="true" OnCheckedChanged="chkboxSelectAll_CheckedChanged"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkCert" AutoPostBack="true" OnCheckedChanged="chkCert_CheckedChanged" OnClick="Javascript:checkForVirtual();" runat="server" />
<input type="hidden" id="hdnCertId" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "CertId") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CertificateID" HeaderText="Certificate ID" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="partID" HeaderText="Part Number" HeaderStyle-HorizontalAlign="Center" />
..............................
</Columns>
.........................
.......................
</asp:GridView>
请有人帮助这个非常感谢我的人。 非常感谢提前..
答案 0 :(得分:0)
<HeaderTemplate>
<asp:CheckBox ID="chkboxSelectAll" AutoPostBack="true" OnCheckedChanged="chkboxSelectAll_CheckedChanged" runat="server" Text="All" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkCert" runat="server" Font-Size="XX-Small" />
</ItemTemplate>
</asp:TemplateField>
在cs文件中
protected void chkboxSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chckheader = (CheckBox)gvPRCertInfo.HeaderRow.FindControl("chkboxSelectAll");
foreach (GridViewRow row in gvPRCertInfo.Rows)
{
CheckBox CheckBoxchckrw = (CheckBox)row.FindControl("chkCert");
if (chckheader.Checked == true)
{
CheckBoxchckrw.Checked = true;
}
else
{
CheckBoxchckrw.Checked = false;
}
}
}
获取按钮点击的详细信息
protected void button_Click(object sender, EventArgs e)
{
try
{
int cnt = 0;
DataTable dt = new DataTable();
dt.Columns.Add("Certificate ID");
dt.Columns.Add("Part Number");
dt.Columns.Add("Part Description");
foreach (GridViewRow row in gvPRCertInfo.Rows)
{
if ((row.Cells[0].FindControl("chkCert") as CheckBox).Checked)
{
DataRow dr = dt.NewRow();
dr["Certificate ID"] = row.Cells[1].Text;
dr["Part Number"] = row.Cells[2].Text;
dr["Part Description"] = row.Cells[3].Text;
dt.Rows.Add(dr);
cnt++;
}
}
if (cnt <= 0)
{
DataRow dr = dt.NewRow();
dr["Certificate ID"] = gvPRCertInfo.SelectedRow.Cells[1].Text;
dr["Part Number"] = gvPRCertInfo.SelectedRow.Cells[2].Text;
dr["Part Description"] = gvPRCertInfo.SelectedRow.Cells[3].Text;
dt.Rows.Add(dr);
}
Session["Details"] = dt;
Response.Redirect("url");
}
catch (Exception ex)
{
}
}
的副本