ASP.NET使用复选框隐藏Gridview行
我试图在ASP.NET页面上创建一个动态Gridview,我有多行,并添加了一个复选框列ASP.NET使用复选框隐藏Gridview行,asp.net,gridview,checkbox,Asp.net,Gridview,Checkbox,我试图在ASP.NET页面上创建一个动态Gridview,我有多行,并添加了一个复选框列 <body> <h1>Alerts</h1> <form id="form1" runat="server"> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KiwiLogConnec
<body>
<h1>Alerts</h1>
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KiwiLogConnectionString %>" SelectCommand="SELECT * FROM [Syslogd]
GROUP BY MsgHostname, MsgDate, MsgTime, MsgPriority, MsgText"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" DataSourceID="SqlDataSource1" ForeColor="#333333" AllowPaging="True" PageSize="15">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField >
<ItemTemplate >
<asp:CheckBox ID ="Checkbox" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="MsgDate" HeaderText="Datum" SortExpression="MsgDate" ItemStyle-Wrap="false" >
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="MsgTime" HeaderText="Tijd" SortExpression="MsgTime" ItemStyle-Wrap="false" >
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="MsgPriority" HeaderText="Priority" SortExpression="MsgPriority" ItemStyle-Wrap="false" >
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="MsgHostname" HeaderText="Hostname" SortExpression="MsgHostname" ItemStyle-Wrap="false" >
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="MsgText" HeaderText="Message" SortExpression="MsgText" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:Button ID="btn_update" runat="server" OnClick="btn_update_Click" Text="Update" />
</form>
</body>
gridview是用SQL数据库构建的,因此它必须是动态的。在福沃德,非常感谢 您可以尝试以下操作:
protected void btn_update_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
if (((CheckBox)gvr.findcontrol("Checkbox")).Checked == true)
{
//Do stuff with checked row
gvr.Visible = false;
}
}
}
我会使用javascript实现类似的功能。哈哈,没问题。另外,您从未在示例中声明过“Checkbox”,而且
.Checked
属性也应该大写。为了安全起见,您可能应该在发布之前在IDE中检查这些内容。@TymeJV,这不起作用。他不知道。检查过的财产。我正在Visual Studio 2012中构建Web表单,您有其他解决方案吗?@BassieBas1987我做了一些编辑。如果有帮助,请告诉我:)
protected void btn_update_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
if (((CheckBox)gvr.findcontrol("Checkbox")).Checked == true)
{
//Do stuff with checked row
gvr.Visible = false;
}
}
}