Links to functions in the CS file inside a GridView

Discussion in 'ASP .Net Web Controls' started by Andy, Apr 30, 2007.

  1. Andy

    Andy Guest

    Hello,

    I'm trying to add a button or a text link(Either will do) to the end of a
    row in a GridView. Then for this button to call a function from the CS file
    attached to it. I know this can be done with a normal ASP button through
    <asp:Button OnClick="FunctionName"></asp:Button>
    However, the button and link functions for the GridView control don't seem
    to have the OnClick functionality.
    Is there any way this can be done?

    // ----- Code -----
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataSourceID="AssignmentDatabase" Width="491px">
    <Columns>
    <asp:ImageField DataAlternateTextField="imageLocation"
    DataImageUrlField="imageLocation">
    </asp:ImageField>

    <asp:BoundField DataField="itemID" HeaderText="itemID"
    SortExpression="itemID" />
    <asp:BoundField DataField="itemName" HeaderText="itemName"
    SortExpression="itemName" />
    <asp:BoundField DataField="price" HeaderText="price"
    SortExpression="price" />
    <!-- Link here -->
    </Columns>
    </asp:GridView>

    // ----- End Code -----

    Thanks,
    Andy
     
    Andy, Apr 30, 2007
    #1
    1. Advertising

  2. Andy

    Teemu Keiski Guest

    Hi,

    put the Button in a TemplateField. This way you'll have it as Button and
    separate Click.

    You can also use ButtonField with a specific command-name , when you "get
    the click" by handling GridView's RowCommand event (it's raised when the
    Button is clicked)

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net



    "Andy" <> wrote in message
    news:...
    > Hello,
    >
    > I'm trying to add a button or a text link(Either will do) to the end of a
    > row in a GridView. Then for this button to call a function from the CS
    > file
    > attached to it. I know this can be done with a normal ASP button through
    > <asp:Button OnClick="FunctionName"></asp:Button>
    > However, the button and link functions for the GridView control don't seem
    > to have the OnClick functionality.
    > Is there any way this can be done?
    >
    > // ----- Code -----
    > <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    > DataSourceID="AssignmentDatabase" Width="491px">
    > <Columns>
    > <asp:ImageField DataAlternateTextField="imageLocation"
    > DataImageUrlField="imageLocation">
    > </asp:ImageField>
    >
    > <asp:BoundField DataField="itemID" HeaderText="itemID"
    > SortExpression="itemID" />
    > <asp:BoundField DataField="itemName" HeaderText="itemName"
    > SortExpression="itemName" />
    > <asp:BoundField DataField="price" HeaderText="price"
    > SortExpression="price" />
    > <!-- Link here -->
    > </Columns>
    > </asp:GridView>
    >
    > // ----- End Code -----
    >
    > Thanks,
    > Andy
     
    Teemu Keiski, May 3, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carlos Albert

    Gridview inside Gridview little problems...

    Carlos Albert, Dec 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,662
    Carlos Albert
    Dec 6, 2005
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,611
    Victor Bazarov
    Jun 21, 2004
  3. Elmo Watson
    Replies:
    0
    Views:
    2,766
    Elmo Watson
    Aug 17, 2006
  4. HockeyFan
    Replies:
    1
    Views:
    1,000
    Masudur
    Jul 4, 2007
  5. beginner
    Replies:
    7
    Views:
    554
    Alex Martelli
    Aug 19, 2007
Loading...

Share This Page