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() + ",";
}
}
}
}
}
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() + ",";
}
}
}
}
}