GridView checkbox 合计?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" DataKeyNames="ljm"
OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" ShowFooter="True">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ljm" HeaderText="ljm" ReadOnly="True" Visible=False />
<asp:BoundField DataField="zz" HeaderText="zz" />
<asp:BoundField DataField="jkrq" HeaderText="jkrq" />
<asp:BoundField DataField="ywzy" HeaderText="ywzy" />
<asp:BoundField DataField="jf" HeaderText="jf" />
<asp:BoundField DataField="df" HeaderText="df" />
</Columns>
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" Font-Size="10pt" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (CheckBox2.Checked == true)
{
cbox.Checked = true;
}
else
{
cbox.Checked = false;
}
}
}
可以实现选择,但是如何能做到在选择行后,在页脚处显示选择行的合计呢?谢谢!
------解决方案--------------------同样用查找控件的方法,把当前所选择行的数据合计起来放在页脚处
------解决方案--------------------if (CheckBox2.Checked == true)
{
cbox.Checked = true;
count+=int.Parse(e.Row.Cells[1].Text);
}