Links to functions in the CS file inside a GridView

A

Andy

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
 
T

Teemu Keiski

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top