My problem is the following:
I have a gridview , and I made a template column with a checkbox inside. Then , obviously , I want to check the value of checkboxes . I'm trying to set rows' visible property to false when that row's checkbox is unselected. I'm always getting null , no matter what I do . So , it must be a problem with the FindControl() , but I think it is perfectly normal .
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DbInteract dbi = new DbInteract("CONNECTION STRING");
GridView1.DataSource = dbi.SqlDA("select * from table");
GridView1.DataBind();
}
protected void ProsseguirBtn_Click(object sender, EventArgs e)
{
if (!IsPostBack)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chk");
if (!cb.Checked)
{
GridView1.Rows[row.RowIndex].Visible = false;
}
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="nome" HeaderText="jhf" />
</Columns>
</asp:GridView>
<asp:Button ID="ProsseguirBtn" runat="server" Text="Button"
onclick="ProsseguirBtn_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
Any help would be highly apreciated . :x Thanks in advance .