Problem injecting javascript in GridView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MJB

    #1

    Problem injecting javascript in GridView


    I have a grid view that is databound to a table with 3 columns. One
    column contains a customer ID. I am trying to add a 4th unbound column
    that contains a button and has a javascript onclick event. I need the
    id from the cusomer id column to use my onclick event. but since my
    onclick event is created using a Template Field I don't know how to get
    the ID to use it in my onclick. If anyone has any suggestions I would
    appreciate it.

    FYI I'm doing this because I'm trying to avoid a postback. I'm trying
    to use ajax to make a call to the server and fill in the customer
    details in a different panel.

    TIA,
    Matt
  • Beemer Biker

    #2
    Re: Problem injecting javascript in GridView

    "MJB" <mb2@email.comw rote in message
    news:%23lX6xiPB HHA.1780@TK2MSF TNGP03.phx.gbl. ..
    >
    I have a grid view that is databound to a table with 3 columns. One
    column contains a customer ID. I am trying to add a 4th unbound column
    that contains a button and has a javascript onclick event. I need the id
    from the cusomer id column to use my onclick event. but since my onclick
    event is created using a Template Field I don't know how to get the ID to
    use it in my onclick. If anyone has any suggestions I would appreciate
    it.
    >
    FYI I'm doing this because I'm trying to avoid a postback. I'm trying to
    use ajax to make a call to the server and fill in the customer details in
    a different panel.
    At the RowDataBound callback, You can add the onclick handler and put the id
    into the argument as in something like this

    Panel thisPanel = (Panel)e.Row.Fi ndControl("ID_M yPanel");
    // assume you have only a panel in your template
    Button thisButton = new Button();
    thisButton.attr ibutes.Add("onc lick","return ButtonHandler(" ' +
    id_from_custome r_data + "'));
    thisPanel.Contr ols.Add(thisBut ton);

    id_from_custome r_data is obtained from the same row# but another column or
    from the actual dataitem if it is not in a cell as in
    DataRowView drv = (DataRowView)e. Row.DataItem;
    id_from_custome r_data = drv["id_cust_da ta"].ToString();

    ...hth..



    --
    =============== =============== =============== =============== ===========
    Beemer Biker joestateson at grandecom dot net

    http://ResearchRiders.org Ask about my 99'R1100RT
    =============== =============== =============== =============== ===========


    Comment

    Working...