satheesh babu

satheesh babu

  • NA
  • 128
  • 309.1k

grid view check box selection

Dec 3 2008 12:11 AM
Hi all,

Here i am using below code for grid view and java script function for check all..
those are working fine.

if i select check all it will select all check boxes in the grid view.
now my query is if uncheck one child check box then i need to uncheck the select all check box and again if check that unchecked check box then again i need to show select all check box will be checked.

and if i select all child check boxes individually this time also need to to show the select all check box will be checked.

below is my gridview and select all javascript function

<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="3" Height="96px" OnSelectedIndexChanged="
GridView1_SelectedIndexChanged"
Style="z-index: 109; left: 133px; position: absolute; top: 278px" Width="639px">
<FooterStyle BackColor="White" ForeColor="#000066" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkbox" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<input id="chkAll" runat="server" onclick="javascript:SelectAllCheckboxes(this);"
type="checkbox" />
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>


and below java script function for check all.

<script language="javascript">

function SelectAllCheckboxes(spanChk){

// Added as ASPX uses SPAN for checkbox

var oItem = spanChk.children;
var theBox= (spanChk.type=="checkbox") ?
spanChk : spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;

for(i=0;i<elm.length;i++)
if(elm[i].type=="checkbox" &&
elm[i].id!=theBox.id)
{
//elm[i].click();

if(elm[i].checked!=xState)
elm[i].click();
//elm[i].checked=xState;

}
}
</script>

how can i achieve the functionality....

please help me....

if you see the yahoo mail inbox then it will come with check boxes. i want same functionality.....

thank you....


Answers (3)