How to get the clientid of a grid column

Rate It (1)

Last post 07-03-2009 4:32 AM by jagjot. 2 replies.

Sort Posts:

  • How to get the clientid of a grid column

    07-03-2009, 3:29 AM

    I have a grid in which i have two template fields with link buttons, on row databound of the grid event i want to get the client id of only these two columns, i want to apply some javascript for only these two columns.

    Dim singleClickButton As LinkButton = DirectCast(e.Row.Cells(3).Controls(0), LinkButton)

    but im not able to get the clientid of these link button controls

    my javascript is being applied to complete row, which i dont want. i just want to apply this java script to particular columns.

    any ideas as to where im going wrong.

     

     

  • Re: How to get the clientid of a grid column

    07-03-2009, 4:28 AM
    Answer
    • Contributor
      2,520 point Contributor
    • SSA
    • Member since 05-07-2009, 7:16 PM
    • Amsterdam, The Nederlands
    • Posts 419

    Try to find out the link button control on RowDataBound:

    if (e.Row.RowType == DataControlRowType.DataRow)
            {

    if (e.Row.RowType == DataControlRowType.DataRow)

    {

    LinkButton singleClickButton = (LinkButton) e.Row.FindControl("YourLinkButtonname");

    if(singleClickButton != null)

    {

    /*You want to add javascript function on this link button*/

    singleClickButton.Attributes.Add("onclick", "YourJavaScriptfunction(' " + singleClickButton.ClientID + " ');");

    }

    }

    }

    Let me know if it helps.

  • Re: How to get the clientid of a grid column

    07-03-2009, 4:32 AM
    Answer
    • Participant
      1,399 point Participant
    • jagjot
    • Member since 10-19-2006, 5:02 AM
    • United Kingdom
    • Posts 749

     In order to apply javascript to the columns or cells you need to use RowdataBound Function of your gridview. try the code below..

            If e.Row.RowType = DataControlRowType.DataRow Then

                 e.Row.Cells(3).Attributes.Add("onmouseover", "JavascriptFunction1()")
                 e.Row.Cells(3).Attributes.Add("onmouseout", "JavascriptFunction2()")

            End If

    Hope its is helpful.

     

    Jagjot Singh
    MCP, CCNA
Page 1 of 1 (3 items)