?
Solved

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

Posted on 2014-12-21
5
Medium Priority
?
643 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
[X]
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
  • 2
  • 2
5 Comments
 
LVL 22

Assisted Solution

by:Mrunal
Mrunal earned 1332 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 668 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 1332 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

752 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