Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-12-21
5
Medium Priority
?
696 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
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.
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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