Solved

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

Posted on 2014-12-21
5
499 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now