473,699 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to work with templatefield checkboxes in GridView?

1 New Member
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
1 3247
Frinavale
9,735 Recognized Expert Moderator Expert
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....th ere 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
2815
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 codehind file and I don't know how to get it work since I did not find any equivalent for "Bind" to use in my ITemplate derived class. For my ItemTemplate, I use (int)((DataRowView)container.DataItem) as equivalent to <%# Eval ...%>
1
9105
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 so I can capture this event to do something about it. The problem is that in the CreateChildControls method, I initialize the GridView and link its RowCommand event to a method (so I can capture the LinkButton Click) but it doesn't work... I put...
1
10439
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 this control in the list of objects in odeBehind page. GridView1 and DropDownList1 are bound to TWO DIFFERENT tables (DataSources). The last column of each row in the GridView is shown as a DropDownList. I want to use the SelectedIndexChanged ...
2
27411
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: <asp:TemplateField > <ItemTemplate> <asp:CheckBox ID="chkNotifierAdd" runat="server"/> </ItemTemplate> </asp:TemplateField>
1
21466
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 the grid). Desired aciton is then taken in response to the button_onclick event relevant to the row in which the checked checkboxes exist. Unfortunate Outcome: Each checkbox returns false for its attribute:checked whether the user has placed a...
1
8056
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 background color for the row. Is there another property I need to set to allow selection for this to work? </div> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"...
1
6733
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 called from a control under a Templatefield. Why is this not the case when the command is from a Buttonfield for example. And, if this so, how can I get the index of the row executing the command. This code works for Buttonfield under the...
1
7172
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 field. After using this, I couldnt see a column supporting hyperlink. In the gridviews first column header, there appears an hyperlink with the first record link displaying. That also only in header overwriting with the first column caption.
1
1742
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, AutoGenerateColumns="True". When I add two columns manually to be able to start drag and drop, the drag and drop works OK, but in GridView1_PreRender() and GridView1_RowCreated() I loose values of GridView1.Rows.Cells.Text and e.Row.Cells.Text, these are ""....
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9172
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.