Solved

How to create an event for a GridView CheckBox TemplateField

Posted on 2010-09-23
4
466 Views
Last Modified: 2012-05-10
I have a number of TemplateFields created as CheckBoxes in a Gridview and need to create an event so that when any one of them is clicked it fires an event.
<asp:TemplateField HeaderText="SD" SortExpression="site_down">
                    <EditItemTemplate>
                        <asp:CheckBox ID="chkSD" runat="server" 
                            Checked='<%# Bind("site_down") %>' />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkSD" runat="server" Checked='<%# Bind("site_down") %>' 
                            Enabled="<%# true %>" />
                    </ItemTemplate>
                    
                </asp:TemplateField>

Open in new window

0
Comment
Question by:dcl120748
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Kaushal Arora earned 500 total points
ID: 33742664
You can give a commandname to all of them in design time and then on the rowcommand event you can catch that particular command name and code for that only.

e.CommandName in the rowcommand name event will give you the commandname of the checkbox.

For help you can check this link:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx

Hope it helps.
0
 

Author Comment

by:dcl120748
ID: 33742847
Thanks for that. I have given them command names and do use them for other purposes. Simply my problem is (and I am running short of time)  that when I click on one of these boxes I need it to fire an event that I can trap. For example when I click on the CheckBox where the ID is "chkSD" (as above) I want to trigger an event. I suspect there is also the issue of 'PostBack' here as well?
0
 

Author Comment

by:dcl120748
ID: 33912310
I have no objection but I am just surprised that for a second time in a row I have asked a question, then responded to a request for further information and then heard absolutely nothing. I am questioning the value of being a premium member.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question