how to select single checkbox in datagrid when multiple pages are there

Posted by Venkat0214 under ASP.NET on 3/20/2009 | Views : 4671 | Status : [Member] | Replies : 2
hi,

how to select single check box in datagrid when multiple pages are there in JavaScript..

i have one in that page i am getting bulk records binding to datagrid.
now my requirement is, i want to select single checkbox . after checking one checkbox if i select another checkbox then i have to show one alert message

saying that "you can select only one" .

my problem is i made "allowPaging" is true for datagrid.. now what happening means in 1st page i can select one checkbox and in 2nd page also i am able to select checkbox..

it should not behave like that.. can anyone help me. then it would be great..bit urgent

Kind Regards
Venkatesh J.




Responses

Posted by: Raja on: 3/20/2009 [Member] Starter

Up
0
Down
This is not your exact answer but this will give you some idea on how to do that.

Create an hidden input field (lets say, alreadyChecked) and on check event of the checkbox specify the value as true and on every paging post back maintain that value. On check event of the checkbox, check for the value inside the hidden field and if its true then a checkbox is already checked otherwise not.

In the same way, you can also maintain a session variable. On check event of the checkbox maintain the value in the hidden field and in the Paging event of the GridView/DataGrid get the value of the hidden field (like Request.Form["alreadyChecked"].ToString()) and specify that value as JavaScript variables

like var alreadyChecked = '<%= Request.Form["alreadyChecked"].TosTring() %>'

And check this variable on every click of the checkbox.

Hope this will give you some idea.

Regards,
Raja, USA

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

Posted by: Majith on: 3/21/2009 [Member] Starter

Up
0
Down
Hi ,
Refer the below code:

you can try this in simple way using AJAX MutuallyExclusiveCheckBoxExtender .

<asp:GridView ID="GrdViewAJAX" runat="server" AutoGenerateColumns="False" Width="290px"
AllowPaging="true" PageSize="5">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
<Ajax:MutuallyExclusiveCheckBoxExtender ID="MutuallyExclusiveCheckBoxExtender1" runat="server"
TargetControlID="chk1" Key="chk1">
</Ajax:MutuallyExclusiveCheckBoxExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns> </asp:GridView>


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

Login to post response