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

Posted on 2011-10-27
Last Modified: 2012-06-21

I'm fairly new to 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
Question by:Codingitup
    1 Comment
    LVL 38

    Accepted Solution

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now