Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to change a gridview cell's value when another cell's checkbox is checked?

Posted on 2014-12-21
5
545 Views
Last Modified: 2014-12-26
One of my gridview column is bool data and bound as Checkbox column.  is there an event that fires when user check the checkbox in the edit mode?  There is a date column that I would like to change the date when user checks the checkbox.  Any way I can do this?  Thanks.
0
Comment
Question by:lapucca
  • 2
  • 2
5 Comments
 
LVL 22

Assisted Solution

by:Mrunal
Mrunal earned 333 total points
ID: 40512472
There are two ways to do this.
One is on calling client side function (in javascript/jquery) like:

<asp:CheckBox ID="chk1" runat="server" onchange="javascript:alertme(this.id);" />

Open in new window

with this you have to create javascript function alertme(chkid){}

and other is you can fire server side event like:

<asp:CheckBox ID="chk1" runat="server" OnCheckedChanged="chk1_CheckedChanged" AutoPostBack="true" />

Open in new window


You can use any scenario fits for your requirement.
0
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 167 total points
ID: 40512773
Hey try this...
protected void chkBox1_CheckedChanged(object sender, EventArgs e) 
{
CheckBox chkbox = (CheckBox)sender; 

GridViewRow Grow = (GridViewRow)chkbox.NamingContainer;
if (chkbox.Checked) 
{
string s1= Grow.Cells[0].Text; 
e.Row.Cells[0].ForeColor = System.Drawing.Color.Red;

string s2 = Grow.Cells[1].Text;
e.Row.Cells[1].ForeColor = System.Drawing.Color.Black;
string s3 = Grow.Cells[2].Text; 
e.Row.Cells[0].ForeColor = System.Drawing.Color.Green;

}
}

Open in new window

0
 

Author Comment

by:lapucca
ID: 40513331
Hi Manoj,
Since the checkbox is created by gridview, I don't iknow it's name.  I clicked on this column's creating code in aspx, select the properties tag and I don't see the Event lightning icon where I can select the Changed event.

Hi Mrunal,
the checkbox column when created in aspx, there is no ID attribute and Intellisense doesn't provide javascript onchange as an option so I wonder maybe because it's inside the gridview control, I can't use javascript on it.

Attached is my gridview control's aspx code snipet.
grid.txt
0
 
LVL 22

Assisted Solution

by:Mrunal
Mrunal earned 333 total points
ID: 40514539
You have to do triggering on checkbox and for that you must handle it's click or checked event.
If checkbox of auto-generated by gridview then you can convert that into ItemTemplate (instead of declaring CheckBoxField) - Declare checkbox in that template and bind that field with "Enabled".

Then you can follow with my first post.

Hope this helps you.
0
 

Author Closing Comment

by:lapucca
ID: 40519200
Thank you. all.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Title # Comments Views Activity
defining NULL or 0 10 44
Add or delete table rows 10 53
ASP.Net MVC Login functions with my own Database and User Tables 2 25
JQuery Detecting page post back 6 6
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

792 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