Crazy Cucumber Crazy Cucumber - 3 years ago 139
ASP.NET (C#) Question

gridview redirect onclick with parameter

I have a gridview with 10+ columns and any number of rows based on the date being selected. The gridview looks like this:
enter image description here

There are several parameters that can be selected that generates this gridview. I am trying to implement an

event on the
Weight Ticket
column. I want to be able to click on individual weight tickets and the page will redirect to a different page that shows that weight ticket's details.

I've tried implementing the following:
e.Row.cells[4].Attribute["onClick"] = redirectFunction

That did not do anything. I am unable to click on the weight ticket.

I would really appreciate any help regarding this.

Optional requirement

This is not asked of me, but I'd like to be able to add something else to this. The redirect is done like this:

Response.Redirect("~/pages/TicketDetails.aspx?wt=" + weightTicket + "&act=" + actionMethod +"&src=" + HttpContext.Current.Request.Url);

is what determines whether the
page allows editing. If the
is set to
, you cannot edit it. If it is set to
, you can. I want to be able to dynamically tell the redirect function that it is a view action or edit action.

It is possible if you can look at the
, or
Load #
columns. If any one of them have
, then it is an
action. If they have a value that is not NA, then it is a view. This is just an additional request. I can always just open it as edit and not worry about all this, but it would be helpful if I could do this too.

Any help would be appreciated.

Thank you

Edit 1:

The line I've written in the question (my attempt) is just a pseudo-code. Here is the actual line in my program:

e.Row.Cells[4].Attributes["onClick"] = "dataCellClick(" + e.Row.Cells[4].ToString() + ", view;";

is the function I am calling which in turn does a redirect. I've tried not calling a function but calling the redirect function right here and that didn't work. So I tried this. The two parameters to the function call is

Edit 2:

The gridview that is already in place is dynamic. By that, I mean:

enter image description here

This is what my designer view looks like for the page. The gridview is selected in the image. It does not have all the columns listed out one by one. It gets the columns AND the rows dynamically from a query.

So, these are all the event handler properties I have:

enter image description here

I can tell you this much though:

The following columns are always existent in the gridview:

  1. In

  2. Out

  3. Load #

  4. Vendor Name

  5. Weight Ticket

  6. Vendor BOL

  7. Truck Gross

  8. Product Net

These columns are standard and in this order.

Answer Source

This portion of your code isn't correct:

e.Row.cells[4].Attribute["onClick"] = redirectFunction

You should edited like this in RowDataBound (I supposed e.Row.Cells[4].Textis page name) :

 e.Row.Cells[4].Attributes["onClick"] = "redirectFunction('"+e.Row.Cells[4].Text+"')";

redirectFunction is JavaScript function like this (redirect to pageName.aspx):

    function redirectFunction(pageName) {
        window.location.href = pageName + ".aspx";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download