Help with Gridview and image button

G

glbdev

Hi,

I posted this question yesterday but didn't get the answer I needed.
I am DESPERATE to get this working so I'm re-posting it because I
don't think I worded it correctly.

I have a GridView which is databound to a table. All the data is
being pulled correctly so there is no problem there.

On each row I have an image button which is attached to a
DataTextField, pulling up a uniqueidentifier for that record. Here is
the HTML for it:

<ASP:BUTTONFIELD BUTTONTYPE="Image" IMAGEURL="~/images/ViewEmps.gif"
TEXT="Button" DATATEXTFIELD="EmployeeNumber"
COMMANDNAME="EmplayeeDetails">
<ITEMSTYLE HORIZONTALALIGN="Center" VERTICALALIGN="Middle"
WRAP="False" />
</ASP:BUTTONFIELD>

When I hover above this button it shows me the correct DataTextField
value for each row. I have the code in place so that when the user
clicks on this button it redirects them to another page. No problem,
everythings fine to this point.

The problem I am having is that I need to get the DATATEXTFIELD value
from the button so I can use it as part of a querystring, such as:
Response.Redirect("EmployeeDetails.aspx?id=" +
button_datatextfield_value)

How can I get this DATATEXTFIELD value? Can anyone help with this?

Again, sorry for the re-post but I, obviously, didn't explain the
problem correctly and I am desperate to get this working since I am
going to be using gridviews on several different pages and am stuck
without it working correctly.

Thanks,
Steve
 
D

Duy Lam

Hi,

I posted this question yesterday but didn't get the answer I needed.
I am DESPERATE to get this working so I'm re-posting it because I
don't think I worded it correctly.

I have a GridView which is databound to a table. All the data is
being pulled correctly so there is no problem there.

On each row I have an image button which is attached to a
DataTextField, pulling up a uniqueidentifier for that record. Here is
the HTML for it:

<ASP:BUTTONFIELD BUTTONTYPE="Image" IMAGEURL="~/images/ViewEmps.gif"
TEXT="Button" DATATEXTFIELD="EmployeeNumber"
COMMANDNAME="EmplayeeDetails">
<ITEMSTYLE HORIZONTALALIGN="Center" VERTICALALIGN="Middle"
WRAP="False" />
</ASP:BUTTONFIELD>

When I hover above this button it shows me the correct DataTextField
value for each row. I have the code in place so that when the user
clicks on this button it redirects them to another page. No problem,
everythings fine to this point.

The problem I am having is that I need to get the DATATEXTFIELD value
from the button so I can use it as part of a querystring, such as:
Response.Redirect("EmployeeDetails.aspx?id=" +
button_datatextfield_value)

How can I get this DATATEXTFIELD value? Can anyone help with this?

Again, sorry for the re-post but I, obviously, didn't explain the
problem correctly and I am desperate to get this working since I am
going to be using gridviews on several different pages and am stuck
without it working correctly.

Thanks,
Steve

Maybe i don't understand properly your idea, so my code no usefull for you.
I think you can give data though CommandAgrument attribute from Button
control.
For example:

[Design]

<asp:button text="click here" CommandAgrument='<%#
Eval("EmployeeNumber") %>' OnClick="OnClickRedirectButton" />

[Code behind]

protected void OnClickRedirectButton(object sender, EventAgrs e) {
Button btn = sender as Button;
int employeeNum = int.Parse( btn.CommandAgrument );
Response.Redirect("EmployeeDetails.aspx?id=" +employeeNum );
}

I hope this post could help you
 
G

glbdev

I posted this question yesterday but didn't get the answer I needed.
I am DESPERATE to get this working so I'm re-posting it because I
don't think I worded it correctly.
I have a GridView which is databound to a table. All the data is
being pulled correctly so there is no problem there.
On each row I have an image button which is attached to a
DataTextField, pulling up a uniqueidentifier for that record. Here is
the HTML for it:
<ASP:BUTTONFIELD BUTTONTYPE="Image" IMAGEURL="~/images/ViewEmps.gif"
TEXT="Button" DATATEXTFIELD="EmployeeNumber"
COMMANDNAME="EmplayeeDetails">
<ITEMSTYLE HORIZONTALALIGN="Center" VERTICALALIGN="Middle"
WRAP="False" />
</ASP:BUTTONFIELD>
When I hover above this button it shows me the correct DataTextField
value for each row. I have the code in place so that when the user
clicks on this button it redirects them to another page. No problem,
everythings fine to this point.
The problem I am having is that I need to get the DATATEXTFIELD value
from the button so I can use it as part of a querystring, such as:
Response.Redirect("EmployeeDetails.aspx?id=" +
button_datatextfield_value)
How can I get this DATATEXTFIELD value? Can anyone help with this?
Again, sorry for the re-post but I, obviously, didn't explain the
problem correctly and I am desperate to get this working since I am
going to be using gridviews on several different pages and am stuck
without it working correctly.
Thanks,
Steve

Maybe i don't understand properly your idea, so my code no usefull for you.
I think you can give data though CommandAgrument attribute from Button
control.
For example:

[Design]

<asp:button text="click here" CommandAgrument='<%#
Eval("EmployeeNumber") %>' OnClick="OnClickRedirectButton" />

[Code behind]

protected void OnClickRedirectButton(object sender, EventAgrs e) {
Button btn = sender as Button;
int employeeNum = int.Parse( btn.CommandAgrument );
Response.Redirect("EmployeeDetails.aspx?id=" +employeeNum );

}

I hope this post could help you

I appreciate your help. Problem is that there is no "onclick" event
for a button on a gridview and "CommandAgrument" seems to give only
the row # associated with that button. I need a button that's on a
gridview (<ASP:BUTTONFIELD BUTTONTYPE="Image") not a regular button
(<asp:button text="click here"), they seem to work differently. I
need to return (or somehow obtain) the DataTextField value that is
assigned to this button.

Any ideas on how to do this?

Thanks,
Steve
 
G

glbdev

Maybe i don't understand properly your idea, so my code no usefull for you.
I think you can give data though CommandAgrument attribute from Button
control.
For example:

<asp:button text="click here" CommandAgrument='<%#
Eval("EmployeeNumber") %>' OnClick="OnClickRedirectButton" />
[Code behind]
protected void OnClickRedirectButton(object sender, EventAgrs e) {
Button btn = sender as Button;
int employeeNum = int.Parse( btn.CommandAgrument );
Response.Redirect("EmployeeDetails.aspx?id=" +employeeNum );

I hope this post could help you
- Show quoted text -

I appreciate your help. Problem is that there is no "onclick" event
for a button on a gridview and "CommandAgrument" seems to give only
the row # associated with that button. I need a button that's on a
gridview (<ASP:BUTTONFIELD BUTTONTYPE="Image") not a regular button
(<asp:button text="click here"), they seem to work differently. I
need to return (or somehow obtain) the DataTextField value that is
assigned to this button.

Any ideas on how to do this?

Thanks,
Steve- Hide quoted text -

- Show quoted text -

Come on, someone, anyone? There has GOT to be a way to do this but I
cannot figure out how. Someone must have done this before.
 
S

Scott Roberts

On each row I have an image button which is attached to a
You say that the value in DATATEXTFIELD is a unique identifier for the row.
And you are able to get the row number in your event handler. So assuming
you have DataKeyNames="EmployeeNumber" on the grid itself, you could do
this:

protected void PaidInvoices_RowClicked(object sender,
CustomGridView.GridViewRowClickedEventArgs args)
{
Response.Redirect("ViewInvoice.aspx?id=" +
PaidInvoices.DataKeys[args.Row.RowIndex].Value.ToString(), true);
}

We use a custom grid view derived from the basic grid view so the event name
and command args are different, but you should get the idea. Basically you
want to inspect "GridView1.DataKeys[rownumber].Value".

Scott
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top