GridView with a copy button (asp.net 2.0)

Last post 10-05-2007 11:59 AM by Charles Asbornsen. 5 replies.

Sort Posts:

  • GridView with a copy button (asp.net 2.0)

    10-05-2007, 9:48 AM
    • Loading...
    • MSchumacher
    • Joined on 07-13-2007, 7:00 PM
    • Montreal, Quebec, Canada
    • Posts 18

    Hi,

    Im trying to add a copy button in a grid view. First, I made a ButtonField that is working perfectly with a OnRowCommand event. Now, I try to do the samething with an image but I didnt found how to do it. I tried with an ImageButton in a TemplateField but I dont find how to fire the OnRowComment event or any other event (OnClick) that I can trap in the code behind.

    Here is a part of the code I used. In this exemple, the ButtonField "Copy" work well and call GridView1_RowCommand in the code behing. But it doesnt work for the templetefield ImageButton.

    Thanks for help

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1"

    CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True" OnRowCommand="GridView1_RowCommand"

    Width="100%" DataKeyNames="UdcTable,Udc">

    <Columns>

    <asp:TemplateField>

    <ItemTemplate>

    <asp:ImageButton runat="server" ID="imageButton" ImageUrl="~/Common/Images/copy.gif" CommandName="CopyButton" CommandArgument="Bidon" />

    </ItemTemplate>

    </asp:TemplateField>

     

    <asp:ButtonField Text="Copy" CommandName="CopyButton" />

    etc...

    M. Schumacher
  • Re: GridView with a copy button (asp.net 2.0)

    10-05-2007, 10:13 AM
    Answer

    I made that sort of thing work with LinkButton.  Inside your item template:

    <asp:LinkButton ID="btnCopy" 
         runat="server" 
         CausesValidation="False" 
         OnClick="btnCopy_Click"
         Tooltip="Copy"
         >
         <asp:Image ID="imgBtnCopy" 
             runat="server" 
             ImageUrl="../../images/copy.gif"
         />
    </asp:LinkButton>

    That help?

    May all your posts be enlightening...
    Charlie Asbornsen
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: GridView with a copy button (asp.net 2.0)

    10-05-2007, 11:08 AM
    • Loading...
    • MSchumacher
    • Joined on 07-13-2007, 7:00 PM
    • Montreal, Quebec, Canada
    • Posts 18

    Thanks Charles,

     Actually, I think my problem maybe more complex than I tought. I found this article : http://zifiglio.blogspot.com/2006/12/imagebutton-control-nested-in-gridview.html 

    I did as it suggest, turning to false the validation, and then I had a postback witn an OnClick. Now, I have to figure what to do with it. I use .net 2.0 and this problem may be solve in 3.0... Im not sure I want to go in this mecanics of binding data on postback only and stuff like that. Im also not sure if I will loose the validation I did. And I have to do again test different solution because I was not aware of this event problem.

    Thanks again,

    Karl

     

    M. Schumacher
  • Re: GridView with a copy button (asp.net 2.0)

    10-05-2007, 11:18 AM

    But mine doesn't use an image button, it uses a link button with an associated image.

    May all your posts be enlightening...
    Charlie Asbornsen
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: GridView with a copy button (asp.net 2.0)

    10-05-2007, 11:38 AM
    • Loading...
    • MSchumacher
    • Joined on 07-13-2007, 7:00 PM
    • Montreal, Quebec, Canada
    • Posts 18

    Sorry Charles,

     Your solution work!  Im able to raise OnClick and OnCommandRow event now. Because I already have a column calling OnCommandRow, I will put all my code there. Now, I will search how to pass the argument (CommandArgument) to have the key and be able to do the copy job.

     Thanks

    M. Schumacher
  • Re: GridView with a copy button (asp.net 2.0)

    10-05-2007, 11:59 AM

    No prob.

    May all your posts be enlightening...
    Charlie Asbornsen
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Page 1 of 1 (6 items)