Solved

onclientclick question for gridview

Posted on 2007-03-22
1
409 Views
Last Modified: 2012-05-05
i have a gridview with checkboxes for each row. I have a button for update on a checked row (I only want to let people update one row at a time). How can I add a confirm update popup or something similar for a checked row with a particular string in a field?

i.e.
checkbox    product     name    status
[]                 p2              bob      active
[]                 p4                          pending

if someone checks the second row I don't need an update confirmation, but if someone checks the first row I'd like a confirmation since the name field is populated....I can't seem to tweak the javascript for the onclientclick to check for the name field populated or not... i get the confirmation alert for all checkboxes by default... any suggestions?
0
Comment
Question by:acdagirl
1 Comment
 
LVL 9

Accepted Solution

by:
bele04 earned 500 total points
ID: 18777790
you can try adding the javascript on the RowDataBound event of the GridView to check if the name column is null/empty or not.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if ( e.Row.RowType == DataControlRowType.DataRow )
        {
            if ( !String.IsNullOrEmpty(e.Row.Cells[2].Text) )
            {
                CheckBox cb = e.Row.FindControls("<name of your checkbox>") as CheckBox;
                cb.Attributes.Add("onchange", "javascript:alert('hey');");
            }
        }
    }
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

19 Experts available now in Live!

Get 1:1 Help Now