Solved

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

Posted on 2014-12-21
5
562 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
VS 2013 installer,  Install, Update and uninstall via SCCM 6 41
ASP.net Markup for Sub Menu 2 39
Header Font Size in Grid View 6 22
C# LINQ 5 18
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
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…

680 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