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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.