ASP.NET 2.0 利用 checkbox获得选中行的行号, 在footer中显示
2008-04-28 13:21 Virus-BeautyCode 阅读(2082) 评论(1) 编辑 收藏 举报
我的思路是添加一个隐藏列,里面放一个textbox控件,用来记录行号,然后在运行的时候取出来显示在footer中。
隐藏列为第一列,checkbox添加到模板列中,利用它的OnCheckedChanged事件执行代码,填充行号到footer
页面代码如下
后台代码如下
测试通过,谢谢1!
隐藏列为第一列,checkbox添加到模板列中,利用它的OnCheckedChanged事件执行代码,填充行号到footer
页面代码如下
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowFooter="True"
DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="rowNumber" runat="server">12</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="True" />
</ItemTemplate>
<FooterTemplate >
<asp:Label ID="lblmsg" runat="server">你点击了第</asp:Label>
</FooterTemplate>
<ControlStyle Width="200px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="rowNumber" runat="server">12</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="True" />
</ItemTemplate>
<FooterTemplate >
<asp:Label ID="lblmsg" runat="server">你点击了第</asp:Label>
</FooterTemplate>
<ControlStyle Width="200px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
后台代码如下
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
//Response.Write();
GridViewRow row = ((CheckBox)sender).Parent.Parent as GridViewRow;
TextBox tb = (TextBox)(row.FindControl("rowNumber"));
GridView1.FooterRow.Cells[1].Text = tb.Text;
//Response.Write(tb.Text);
}
{
//Response.Write();
GridViewRow row = ((CheckBox)sender).Parent.Parent as GridViewRow;
TextBox tb = (TextBox)(row.FindControl("rowNumber"));
GridView1.FooterRow.Cells[1].Text = tb.Text;
//Response.Write(tb.Text);
}
测试通过,谢谢1!