Hi all,
I need your help.
In my gridview I inserted a column that contains a checkbox in the header
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader" Text="<br />Select"
AutoPostBack="true" OnCheckedChanged="chkBxHeader1_CheckedChanged" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<div>
<br />
<asp:CheckBox ID="chkRow" runat="server" Enabled="false" />
<asp:ImageButton ID="btnchkRow"
ImageUrl="/img/checkbox_closed.gif"
runat="server" />
</div>
</ItemTemplate>
Selecting this checkbox will perform the following procedure chkBxHeader1_CheckedChanged which follows the validation of the gridview rows
try
{
CheckBox chkBxHeader = (CheckBox)sender;
bool isvalid = false;
foreach (GridViewRow row in gvProducts.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
if (!(row.FindControl("chkRow") as CheckBox).Checked)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert",
"alert('KO');", true);
chkBxHeader.Checked = false;
isvalid = false;
break;
}
else
{
chkBxHeader.Checked = true;
chkBxHeader.Enabled = false;
isvalid = true;
}
}
}
// Process only if valid.
if (isvalid)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert",
"alert('OK');", true);
}
}
catch (Exception ex)
{
Console.WriteLine("Skipped exception! " + ex);
}
If the procedure is successful i have to disable the checkbox in the column header, how can i do it?
I need to disable the checkbox in the column header of my gridview when only if the results count is 9.
I have tried this in GridView1_RowDataBound, without success:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Header)
{
int counter = 0;
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
if (chkRow.Checked)
{
counter++;
}
}
if (counter == 9)
{
CheckBox chkBxHeader = (CheckBox)e.Row.FindControl("chkBxHeader");
Response.Write(counter + "<br />");
chkBxHeader.Visible = false;
}
}
}
catch (Exception ex)
{
Console.WriteLine("Skipped exception! " + ex);
}
}
Thanks in advance for any help or suggestion.