Reputation: 7163
I have a button in my rows in a gridview and when clicking the button some code behind handles the button click. I want to pass a commandname paramater through with each button click, which is really just an order id. I'm wondering how I can set the commmand name for each button.
<Columns>
<asp:BoundField DataField="status" HeaderText="Status" HeaderStyle-HorizontalAlign="Left" SortExpression="status" />
<asp:BoundField DataField="orderid" HeaderText="Order ID" HeaderStyle-HorizontalAlign="Left" SortExpression="orderid" />
<asp:BoundField DataField="customer" HeaderText="Customer" HeaderStyle-HorizontalAlign="Left" SortExpression="customer" />
<asp:BoundField DataField="email" HeaderText="Email" HeaderStyle-HorizontalAlign="Left" SortExpression="email" />
<asp:BoundField DataField="createddate" HeaderText="Created Date" HeaderStyle-HorizontalAlign="Left" SortExpression="createddate" />
<asp:BoundField DataField="promocode" HeaderText="Promo Code" HeaderStyle-HorizontalAlign="Left" SortExpression="promocode" />
<asp:BoundField DataField="grandtotal" HeaderText="Grand Total" HeaderStyle-HorizontalAlign="Left" SortExpression="grandtotal" DataFormatString="{0:C}"/>
<asp:ButtonField Text="View" CommandName="6182" ButtonType="Button" />
</Columns>
As you can see abve the last column is the button that appears on each row and I've currently set it to 6182 - just as an example. What I really want to set it to is the orderid value...
How can I do that?
Thanks,
Upvotes: 0
Views: 2977
Reputation: 1571
I'd probably go for something similar to this:
<asp:ButtonField Text="View" CommandName='<%# Eval("orderid") %>' ButtonType="Button" />
That should insert the orderid
for the bound row into that field. If it doesn't work, convert the column into a TemplateField
, add a button and do the same. Report back :-)
Upvotes: 2