Get value from an image button in a row in GridView

G

glbdev

Hi.

I have a gridview in which each row has an image button attached. I
have each button in each row set up to be associated with a DB field.
When I hover above the button it shows me the correct value of the DB
field in a tooltip, so there is no problem there. But ...how do I
access that value? When the user clicks that button I will redirect
him to a new page and I need to use the value as an ID in a
querystring, but cannot figure out how to retrieve it. Everything
else (except optaining the value) works fine. I searched online but
cannot find the answer.

Any help?

Thanks,
Steve
 
S

Siva M

Using PostbackUrl property:

<asp:ImageButton runat="server" ID="ib" ToolTip='<%# Eval("ID") %>'
PostBackUrl='<%# "EditPage.aspx?ID=" + Eval("ID") %>' />

Hope this helps?
 
G

glbdev

Using PostbackUrl property:

<asp:ImageButton runat="server" ID="ib" ToolTip='<%# Eval("ID") %>'
PostBackUrl='<%# "EditPage.aspx?ID=" + Eval("ID") %>' />

Hope this helps?








- Show quoted text -


Siva,

That would work on an image button, but I need it to work on a
Gridview's button control: <ASP:BUTTONFIELD BUTTONTYPE="Image"

Any ideas on that?

Thanks,
Steve
 
J

Joe Stateson

Siva,

That would work on an image button, but I need it to work on a
Gridview's button control: <ASP:BUTTONFIELD BUTTONTYPE="Image"

Any ideas on that?

Thanks,
Steve

The RowCommand autopostback has the row number (e.CommandArguement) and you
can use that to access a cell that has the id as in
GridView1.Rows[nRow].Cells[nCell].Text Sometimes instead of finding a
control that holds the id it is easier to just add the id as an extra column
and use the css style to hide it since it is not used except to make the id
easier to get access to.

If you want to do this on the client side and avoid a postback then during
the RowDataBound you can add something like

strVal = " WHERE id=" + e.Row.Cells[vFieldNum].Text;
e.Row.Cells[nFieldNum].Attributes.Add("onclick", "return
LaunchInfo('./DetailLocation.aspx?sqlDetail=" + strVal+ "\')");

However, it would seem that what Siva suggested should work also


--
======================================================================
Joseph "Beemer Biker" Stateson
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

Top