Maverick_Cool
asked on
How to add "select all " Checkbox in combobox column header
Hi,
I have Datagridview with a combobox column, i need to add a checkbox to the header of this column. if user selects(Checks) this header checbox then all the checkboxes of this column should be selected. And if user Deselects(not Checked) then all the checkboxes of this column should be deselected.
Basically i need to implement select all/Deselect all feature........I am new to datagridview.
Please provide examples and sample code.
Thanks in advance.
I have Datagridview with a combobox column, i need to add a checkbox to the header of this column. if user selects(Checks) this header checbox then all the checkboxes of this column should be selected. And if user Deselects(not Checked) then all the checkboxes of this column should be deselected.
Basically i need to implement select all/Deselect all feature........I am new to datagridview.
Please provide examples and sample code.
Thanks in advance.
Oh, I didn't notice the DataGridView (winforms). Sorry the code above is for ASP.NET. However, you could still use the Javascript implementation in there for your DataGridView.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Alfred1,
Thanks a lot for ur reply. Your suggestion helped me to do my task.
Thanks a lot for ur reply. Your suggestion helped me to do my task.
Glad to help. :-)
Goodluck with your projects. :-)
Goodluck with your projects. :-)
ASKER
I got the partial results.
Javascript:
<script language="javascript" type="text/javascript">
function SelectAllCheckboxes(spanCh
var oItem = spanChk.children;
var theBox=(spanChk.type=="che
xState=theBox.checked;
elm=theBox.form.elements;
for(i=0;i<elm.length;i++)
if(elm[i].type=="checkbox"
{
//elm[i].click();
if(elm[i].checked!=xState)
elm[i].click();
//elm[i].checked=xState;
}
}
</script>
//Check the template field Action below. Thiis is link to the javascript above
<asp:GridView ID="gvTest" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False
ForeColor="#333333" GridLines="None" Width="856px">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Left" />
<Columns>
<asp:TemplateField HeaderText="Action">
<EditItemTemplate>
<asp:CheckBox ID="chkAction" runat="server" />
</EditItemTemplate>
<HeaderTemplate>
<input id="chkAll" runat="server" onclick="javascript:Select
type="checkbox" value="Action" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkAction" runat="server" />
</ItemTemplate>
</asp:TemplateField>
I hope this helps.