我明明在页面上选中了,但加断点走的时候发现checked都等于false
<asp:GridView ID ="GrV_NewInspect" runat ="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames ="qyid" OnSelectedIndexChanged="GrV_NewInspect_SelectedIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" OnSelectedIndexChanging="GrV_NewInspect_SelectedIndexChanging" Width="728px" >
<HeaderStyle Height="18px" ForeColor="black" Font-Overline="False" HorizontalAlign="Center"/>
<Columns >
<asp:TemplateField >
<ItemTemplate >
<asp:CheckBox ID="cbSelect" runat ="server" />
</ItemTemplate>
<ItemStyle Width ="3%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="企业名称">
<ItemTemplate>
<asp:LinkButton ID="LinkBn_CoName" runat="server" CommandName="select" Text='<%# Eval("qymc") %>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="270px" />
</asp:TemplateField>
<asp:BoundField DataField ="jcry" HeaderText ="检查人" SortExpression ="jcry" >
<ItemStyle Width="70px" />
<HeaderStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField ="jctzsbh" HeaderText ="检查通知书编号" SortExpression ="jctzsbh" >
<ItemStyle Width="100px" />
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField ="jcrq" HeaderText ="检查日期" SortExpression ="jcrq">
<ItemStyle Width="100px" />
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:TemplateField HeaderText="待上报数据" >
<ItemTemplate>
<p style="color:#2D7384;">待上报数据</p>
</ItemTemplate>
<ItemStyle Width ="70px" />
</asp:TemplateField>
</Columns>
<pagertemplate>
<table width="100%" id="pageC" >
<tr>
<td style="text-align:right;">
第<asp:Label id="lblPageIndex" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共<asp:Label id="lblPageCount" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" />
<asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />
<asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
<asp:linkbutton id="btnLast" runat="server" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" />
</td>
</tr>
</table>
</pagertemplate>
</asp:GridView> System.Text.StringBuilder sb = new System.Text.StringBuilder(" insert into inspect_dsb select QYID, QYMC, jctzsbh,jcmd,jcyj,jcnr,jcjl,jcry, 1,sysdate from inspect_tmp where");
int n = 0;
for (int i = 0; i < GrV_NewInspect.Rows.Count; i++) //循环gridview一页中的每行,知道哪些行被选中
{ GridViewRow row = GrV_NewInspect .Rows[i];
CheckBox cbox = (CheckBox)row.FindControl("cbSelect");
if (cbox.Checked == true)
{
n++;
if (n == 1)
{
sb.Append(" qyid=" + GrV_NewInspect.DataKeys[i].Value);
}
else
{
sb.Append(" or qyid=" + GrV_NewInspect.DataKeys[i].Value);
}
}
}
if (n > 0) //判断,如果有行被选中则执行删除
{
oracleHelper oh = new oracleHelper();
string sql = sb.ToString();
oh.RunSQLDirect(sql);
}
ph.delectTheSelected(GrV_NewInspect, "cbSelect", "inspect_tmp", "qyid");
bindGrv(hf_search.Value, hf_fr.Value);
大家帮我看看我错在哪里,谢谢 ^_^
<asp:GridView ID ="GrV_NewInspect" runat ="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames ="qyid" OnSelectedIndexChanged="GrV_NewInspect_SelectedIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" OnSelectedIndexChanging="GrV_NewInspect_SelectedIndexChanging" Width="728px" >
<HeaderStyle Height="18px" ForeColor="black" Font-Overline="False" HorizontalAlign="Center"/>
<Columns >
<asp:TemplateField >
<ItemTemplate >
<asp:CheckBox ID="cbSelect" runat ="server" />
</ItemTemplate>
<ItemStyle Width ="3%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="企业名称">
<ItemTemplate>
<asp:LinkButton ID="LinkBn_CoName" runat="server" CommandName="select" Text='<%# Eval("qymc") %>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="270px" />
</asp:TemplateField>
<asp:BoundField DataField ="jcry" HeaderText ="检查人" SortExpression ="jcry" >
<ItemStyle Width="70px" />
<HeaderStyle Width="70px" />
</asp:BoundField>
<asp:BoundField DataField ="jctzsbh" HeaderText ="检查通知书编号" SortExpression ="jctzsbh" >
<ItemStyle Width="100px" />
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField ="jcrq" HeaderText ="检查日期" SortExpression ="jcrq">
<ItemStyle Width="100px" />
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:TemplateField HeaderText="待上报数据" >
<ItemTemplate>
<p style="color:#2D7384;">待上报数据</p>
</ItemTemplate>
<ItemStyle Width ="70px" />
</asp:TemplateField>
</Columns>
<pagertemplate>
<table width="100%" id="pageC" >
<tr>
<td style="text-align:right;">
第<asp:Label id="lblPageIndex" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共<asp:Label id="lblPageCount" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" />
<asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />
<asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
<asp:linkbutton id="btnLast" runat="server" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" />
</td>
</tr>
</table>
</pagertemplate>
</asp:GridView> System.Text.StringBuilder sb = new System.Text.StringBuilder(" insert into inspect_dsb select QYID, QYMC, jctzsbh,jcmd,jcyj,jcnr,jcjl,jcry, 1,sysdate from inspect_tmp where");
int n = 0;
for (int i = 0; i < GrV_NewInspect.Rows.Count; i++) //循环gridview一页中的每行,知道哪些行被选中
{ GridViewRow row = GrV_NewInspect .Rows[i];
CheckBox cbox = (CheckBox)row.FindControl("cbSelect");
if (cbox.Checked == true)
{
n++;
if (n == 1)
{
sb.Append(" qyid=" + GrV_NewInspect.DataKeys[i].Value);
}
else
{
sb.Append(" or qyid=" + GrV_NewInspect.DataKeys[i].Value);
}
}
}
if (n > 0) //判断,如果有行被选中则执行删除
{
oracleHelper oh = new oracleHelper();
string sql = sb.ToString();
oh.RunSQLDirect(sql);
}
ph.delectTheSelected(GrV_NewInspect, "cbSelect", "inspect_tmp", "qyid");
bindGrv(hf_search.Value, hf_fr.Value);
大家帮我看看我错在哪里,谢谢 ^_^
if (!IsPostBack)
{
//原始绑定
}
{
绑定一下!
}
要不就不对了!