How to access controls which are placed in datagrid Header Templete

U

upendra

Hi,
I am B.V.Ramesh Babu.I am working as software programmer using .net.We
are using asp.net1.1 with C#.net as coding.I hope that i will get the
required support from you.
Here is my requirement.
I am using datagrid control.In that data grid I put checkboxes in both
item templete and in Header templete.My requirement is is if i check
any checkbox in itemtemplete and click delete button those records will
be deleted.In another way I check the check box in the Header templete
The all check boxes will be checked and if dechecked all check boxes
will be deleted.
For that purpose I took check box in header templete.But I am unable
access the check box in the header templete of the datagrid
I use the following html code.
---------------------------------------------------------HTML-------------------------------------------------
<table>
<TR>
<TD>
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 176px;
POSITION: absolute; TOP: 104px"
runat="server" Width="688px" Height="248px"
AutoGenerateColumns="False">
<AlternatingItemStyle BackColor="#FFFFCC"></AlternatingItemStyle>
<ItemStyle BackColor="#FF99CC"></ItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#CCFFFF"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:CheckBox id="CheckBox2" runat="server"></asp:CheckBox>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="BankID" ReadOnly="True"
HeaderText="BankID"></asp:BoundColumn>
<asp:BoundColumn DataField="BankName"
HeaderText="BankName"></asp:BoundColumn>
<asp:BoundColumn DataField="CountryName"
HeaderText="Country"></asp:BoundColumn>
<asp:BoundColumn DataField="CityName"
HeaderText="City"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</TD>
</TR>
</table>
---------------------------------------------------------HTML-------------------------------------------------

I use follwing C# code for accessing the check box in header control
---------------------------------------------------------C#-----------------------------------------------------
PAGELOAD
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
bindgrid();
}
foreach(DataGridItem dgi in DataGrid1.Items)
{
CheckBox Hchk=(CheckBox)dgi.FindControl("CheckBox2");
if(Hchk.Checked)
{
Response.Write("HEDER CXHECK BOX IS CHECKED");
}
}
}
BINDGRID FUNCTION
private void bindgrid()
{
SqlDataAdapter da=new SqlDataAdapter("select * from BANKS1",con);
da.Fill(ds,"Banks");
DataGrid1.DataSource=ds.Tables["Banks"];
DataGrid1.DataBind();
}
---------------------------------------------------------C#-----------------------------------------------------


Please help me in this regard.
I would like to access the control which is placed in Headeritem of the
datagrid.
-Thanks in Advance,
Ramesh Babu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top