• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 519
  • Last Modified:

Pass gridview column 0 to command argument of imagebutton in gridview.


I'm fairly new to asp.net but hopefully i'll be able to explain it lol.

I've got the following code: -

<%@ Page Title="" Language="C#" MasterPageFile="~/Global.Master" AutoEventWireup="true" CodeBehind="CurrentRushOrders.aspx.cs" Inherits="Reporting.CurrentRushOrders" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ph_Content" runat="server">
    <h2>Current Rush Orders</h2>
      <asp:GridView ID="GridViewRushOrders" runat="server"  
            Caption="Current Rush Orders on System" AutoGenerateColumns="False"
                  <asp:BoundField DataField="Work Order" HeaderText="Work Order"
                        SortExpression="Work Order" ReadOnly="True" />
                  <asp:BoundField DataField="Sales Order" HeaderText="Sales Order"
                        SortExpression="Sales Order" ReadOnly="True" />
                  <asp:BoundField DataField="Line No" HeaderText="Line No" ReadOnly="True"
                        SortExpression="Line No" />
                  <asp:BoundField DataField="Qty" HeaderText="Qty" ReadOnly="True"
                        SortExpression="Qty" />
                  <asp:BoundField DataField="Customer Name" HeaderText="Customer Name"
                        SortExpression="Customer Name" ReadOnly="True" />
                  <asp:BoundField DataField="Requested Date" HeaderText="Requested Date"
                        ReadOnly="True" SortExpression="Requested Date" />
                  <asp:BoundField DataField="Priority" HeaderText="Priority"
                        SortExpression="Priority" ReadOnly="True" />
                  <asp:BoundField DataField="Part Number" HeaderText="Part Number"
                        SortExpression="Part Number" ReadOnly="True" />
                  <asp:BoundField DataField="Status Next" HeaderText="Status Next"
                        SortExpression="Status Next" ReadOnly="True" />
                  <asp:BoundField DataField="Carrier" HeaderText="Carrier"
                        SortExpression="Carrier" />
                  <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/cancel_48.png" EditImageUrl="~/Images/edit_48.png"
                        ShowEditButton="True" UpdateImageUrl="~/Images/save_48.png" />
                  <asp:TemplateField ShowHeader="False">
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false"
                        CommandName="Shipped" ImageUrl="~/Images/autoship_48.png" Text="shipped" CommandArgument="<% COLUMN 0 of GRIDVIEW %>" />
                        <asp:ConfirmButtonExtender ID="Button1_ConfirmButtonExtender" runat="server"
                            ConfirmText="Are you sure you want to assign this order as shipped?" Enabled="True" TargetControlID="ImageButton1">
      <br />
      <asp:SqlDataSource ID="SqlDataSourceRushOrders" runat="server"
            ConnectionString="<%$ ConnectionStrings:jdeConnectionString %>" SelectCommand="
(MY SQL CODE BLANKED"></asp:SqlDataSource>
      <br />

    <br />
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <br />
      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
      <br />
      <br />

      <br />

And the following c# Code: -

        protected void GridViewRushOrders_RowCommand(object sender, GridViewCommandEventArgs  e)
            Label1.Text = e.CommandArgument.ToString();


I want to display column 0 of the corisponding row (WorkOrder) on label1.text when the ImageButton1 is pressed on the gridview.

Hope this makes sense.

Best Regards
1 Solution
Tom BeckCommented:
Try this:
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false"
                        CommandName="Shipped" ImageUrl="~/Images/autoship_48.png" Text="shipped" CommandArgument='<%# Eval("Work Order") %>' />

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now