Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindControl() not working

Status
Not open for further replies.

tathagat

Programmer
Jan 29, 2002
5
US
Hi,
I am new to ASP.NET and trying to implement the delete the selected rows from datagrid. To check the selected rows I am using checkbox (template column) but when i use to find whether it has been selected or not, it always returns "False". (deleteChkBxItem.Checked) is always false.

Here is the code please help me.
1. CheckBox in Grid
//////HTML/////////
<asp:TemplateColumn>
<HeaderTemplate> <asp:CheckBox id="chkAll" Onclick="javascript:return SelectAllCheckboxes(this.checked,this.id);"runat="server" AutoPostBack="false" ToolTip="Select/Deselect All" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox id="chkSelect" runat="server" AutoPostBack="false" /> </ItemTemplate>

2. DeleteAll button
----------------------
<asp:Button id="butDeleteAll" CssClass="StandardButton" runat="server" Text="Delete All"></asp:Button></td>

3. Code
--------------------
private void butDeleteAll_Click(object sender, System.EventArgs e)
{
string steAsset = "";
bool blnDelete;
int j=-1;
foreach (DataGridItem i in this.AssetSearchDataGrid.Items)
{ CheckBox deleteChkBxItem = (CheckBox)i.FindControl("chkSelect");
if(deleteChkBxItem!=null)//---Always False /////
{
if (deleteChkBxItem.Checked)
{
steAsset=AssetSearchDataGrid.DataKeys[j].ToString();

// Concatenate DataGrid item with comma for SQL Delete
//dgIDs += ((Label) i.FindControl ("StoreID")).Text.ToString() + ",";
}
}
}
}
}
 
Do you check if the page is posting back on your page_load? My guess is that you don't and the datagrid is being re-bound and therefore the checkbox is always false.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Hi,
Thaks a lot "ca8msm". It would have been very easy for you..:). Now I can realize, I have to learn a lot to understand the effect of postback event.
Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top