how to use checkbox in griedview in asp..net

Posted by Shanky11 under ASP.NET on 2/28/2013 | Points: 10 | Views : 727 | Status : [Member] | Replies : 2
ths is my griedview --------------------i want if i selectall all ckbox should get selected---------------

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"

AllowPaging="true" DataKeyNames="messageuid">

<Columns>

<asp:TemplateField HeaderText="Select">
<HeaderTemplate >
<asp:CheckBox ID="chkSelectall" runat="server" Text="Select All" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>

</asp:TemplateField>
<asp:BoundField HeaderText="MessageID" DataField="messageuid" />
<asp:BoundField HeaderText="Messages" DataField="message" />
</Columns>

</asp:GridView>




Responses

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
http://www.aspdotnet-suresh.com/2012/09/check-uncheck-all-checkboxes-in.html

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: mohammedr88-18313 on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
first add an onclick event

<asp:CheckBox ID="chkSelectall" runat="server" Text="Select All" OnClick="selectAll2(this)"/>


then write a java script function
<script language="javascript" type="text/javascript">
function selectAll2(involker) {
var inputElements = document.getElementsByTagName('input');
for (var i = 0; i < inputElements.length; i++) {
var myElement = inputElements[i];
if (myElement.type === "checkbox") {
if (myElement.id.substr((myElement.id.length - 9), myElement.id.length) == "chkSelect") {
myElement.checked = involker.checked;
}
}
}


thats it enjoyy



Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response