Problem injecting javascript in GridView

M

MJB

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
 
B

Beemer Biker

MJB said:
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.FindControl("ID_MyPanel");
// assume you have only a panel in your template
Button thisButton = new Button();
thisButton.attributes.Add("onclick","return ButtonHandler("' +
id_from_customer_data + "'));
thisPanel.Controls.Add(thisButton);

id_from_customer_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_customer_data = drv["id_cust_data"].ToString();

...hth..



--
=======================================================================
Beemer Biker joestateson at grandecom dot net
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
=======================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top