Link to home
Start Free TrialLog in
Avatar of Wizilling
WizillingFlag for New Zealand

asked on

gridview and confirmbuttonextender

Hi, I have a gridview and a custom code delete button in my asp.net page.
The delete button fires confirmbuttonextender control when click . This is working fine and I see the dialog box asking whether to continue with delete or not.

What I want to do is , when the delete button is click, The selected row is highlight and then the confirm button extender control to be called.

I tried rowcommand but that fires after.

I am using c# and asp.net .
Avatar of Alfred A.
Alfred A.
Flag of Australia image

Hi,

You can use javascript to change row color and once you've created your javascript function, you can then attached this to the onclick event of the select button in your gridview (which I guess is your targetcontrolid in your confirmbutton extender) through the RowCreated event of your GridView.

In your Design - Source, add this javascript

<script language ="javascript" type="text/javascript">
    var oldColor = '';
    var currentRowID;
    var currentColor;
    var previousRowID;
    var previousColor = '';

function ChangeRowColor(rowID)
{
    var color = document.getElementById(rowID).style.backgroundColor;

    currentRowID = rowID;
    currentColor = color;

    if (currentRowID == previousRowID)
        return;

    if (previousRowID != null) {
        //Return previous row to original state
        document.getElementById(previousRowID).style.backgroundColor = previousColor;
    }

    document.getElementById(rowID).style.backgroundColor = 'blue';
   
    previousColor = currentColor;
    previousRowID = currentRowID;
}

</script>


In your code-behind, do this something like this where btnSelect is the targetcontrolid

private void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {
        string rowID = String.Empty;
        Button btnSelect;
        if ((e.Row.RowType == DataControlRowType.DataRow)) {
            btnSelect = ((Button)(e.Row.FindControl("btnSelect")));
            rowID = ("row" + e.Row.RowIndex.ToString);
            e.Row.Attributes.Add("id", ("row" + e.Row.RowIndex.ToString));
            btnSelect.Attributes.Add("onclick", ("ChangeRowColor(" + ("\'"
                            + (rowID + ("\'" + ")")))));
        }
    }

I hope this helps.

Avatar of Wizilling

ASKER

Hi, Nothing happens..
I changed this bit --- e.Row.FindControl("btnSelect")

the confirm button extender still fires first and the color of the row doesnt change to blue.
ASKER CERTIFIED SOLUTION
Avatar of Alfred A.
Alfred A.
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial