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 .
LVL 13
WizillingAsked:
Who is Participating?
 
Alfred A.Commented:
Hi,

OK.  Before I provide with another alternative (tweaking about ClientScript.GetPostBackEventReference) regarding what I provided in the previous post.

I am posting another alternative that I believe is better and lighter than what I was proposing in the previous post.

Consider the following approach.

In your Design - Source, add this javascript

<script language ="javascript" type="text/javascript">
    function Highlight_On(obj)
    {
        if(obj != null)
        {
            obj.originalBgColor = obj.style.backgroundColor;
            obj.style.backgroundColor='blue';
        }
    }  


    function Highlight_Off(obj)
    {
        if(obj != null)
        {
            obj.style.backgroundColor = obj.originalBgColor;
        }
    }
</script>


In your code-behind, do something in the RowDataBound event

Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        Dim btnSelect As Button
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            btnSelect = CType(e.Row.FindControl("btnSelect"), Button)
            e.Row.Attributes.Add("onmouseover", "Highlight_On(this);")
            e.Row.Attributes.Add("onmouseout", "Highlight_Off(this);")
            btnSelect.Attributes.Add("onclick", "Highlight_On(this);")
        End If
End Sub


Test it out.   I hope this helps.
0
 
Alfred A.Commented:
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.

0
 
WizillingAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.