简体   繁体   中英

setting a commandname in gridview buttonfield

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,

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 :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM