473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to work with templatefield checkboxes in GridView?

1
Here's my data: (Table: EmployeePlan)
Expand|Select|Wrap|Line Numbers
  1. EmpID     Plan      Status
  2. abc123    PlanA     A
  3. abc123    PlanB     D
  4. abc123    PlanC     A
  5. xyz789    PlanA     D
  6. xyz789    PlanB     D
  7. xyz789    PlanC     A
  8. ...
where Status "A" means an employee subscribed to a certain plan and "D" otherwise.

I have created a GridView in ASP.Net, normalising the data by the query:
Expand|Select|Wrap|Line Numbers
  1. select EmpID,
  2. sum(case when Plan='PlanA' and Status='A' then 1 else 0 end) as PlanA,
  3. sum(case when Plan='PlanB' and Status='A' then 1 else 0 end) as PlanB,
  4. sum(case when Plan='PlanC' and Status='A' then 1 else 0 end) as PlanC
  5. from EmployeePlan
  6. group by EmpID
and the GridView looks like this:
Expand|Select|Wrap|Line Numbers
  1. Employee ID    Plan A        Plan B        Plan C
  2. abc123            x                _                x
  3. xyz789            _                _                x
  4.  
where "x" is a checked checkbox and "_" is a non-checked checkbox

the checkbox is preset in templatefield by evaluating it (1 = true, 0 = false)

My problems are:

1. How to get the checkbox value from the GridView? (I got the object reference not set error)

2. When a user click the Update button, how to override the UpdateCommand by updating 3 rows instead of updating a single row?
(Update EmployeePlan set Status = @Status where EmpID = @EmpID)

Thanks in advance.
Dec 23 '09 #1

✓ answered by Frinavale

Answer for question 1)
You use the FindControl method for the GridViewRow that contains the checkbox in order to retrieve the checkbox that you want to work with.

Answer for question 2)
You need to implement a method that handles the RowUpdating Event.

All the information you need on the GridView and any other .NET controls can be found in the MSDN Library. This resource should get you pointed in the right direction....there are multiple articles on the GridView there. I recommend bookmarking the MSDN Library and using it as your primary resource when developing in .NET.


-Frinny

1 3233
Frinavale
9,735 Expert Mod 8TB
Answer for question 1)
You use the FindControl method for the GridViewRow that contains the checkbox in order to retrieve the checkbox that you want to work with.

Answer for question 2)
You need to implement a method that handles the RowUpdating Event.

All the information you need on the GridView and any other .NET controls can be found in the MSDN Library. This resource should get you pointed in the right direction....there are multiple articles on the GridView there. I recommend bookmarking the MSDN Library and using it as your primary resource when developing in .NET.


-Frinny
Dec 23 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dieter | last post by:
Two-way databinding (as described in http://dotnetjunkies.com/QuickStartv20/aspnet/doc/data/templates.aspx) works fine for me if I use it within aspx-files. However, I would like to use it my...
1
by: Zule | last post by:
Hi, I am creating a Composite Control within which I have a GridView. In this GridView, I have three TemplateFields, the last one being a template with a LinkButton which is meant to be clicked...
1
by: Nam | last post by:
I have a DropDownList control in a TemplateField inside my GridView How do I access this control’s SelectedIndexChanged event in codeBehind page? I don’t see the ID “DropDownList1” of...
2
by: Tony Hedge | last post by:
This seems more diffciult than it should be, can someone provide any insight? Platform is VB 2005, gridview on a web page. I have this code in the aspx file of a GridView control: ...
1
by: mercercreek | last post by:
This one should be easy. Hope someone has a clue. Simple Scenario: Gridview with mulitple rows, each row with a checkbox. The user checks boxes of her choice. Clicks a button on the form (not in...
1
by: jobs | last post by:
I can't seem to get selectedrowstyle-backcolor to set the row background color unless I force the selected index in the code behind. When i select the ButtonField Run button it does set the...
1
by: jobs | last post by:
CommandArgument does not contain row index when command under Templatefield of- Gridview It appears CommandArgument passed to the rowcommand event does not contain row index when the command is...
1
by: Valli | last post by:
Hi, I need to display an hyperlink column in gridview where if the user clicks that column the page should move to the selected page. I have got help from this group & started using template...
1
by: mghihor | last post by:
Dear GridView Experts! I have problems with GridView when adding a column using TemplateField. I fill GridView1 from a stored procedure. It has a Select statement and returns 14 columns,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.