Using two asp: ButtonColumns in one row of datagrid

Source: Internet
Author: User

Source: http://www.imcoder.org/starter/198821.htm

 

Q:

Hi All

I am having trouble distinguishing between two "buttons"/"links" in my datagrid. It seems to bring back the same information to the ItemCommand. Is there any other way to do this? (Having two linked columns on every line of a datagrid). this is a demonstation:

<

Asp: BoundColumn Visible = "False" DataField = "orders_orderno" SortExpression = "orders_orderno"> </asp: BoundColumn>
<Asp: BoundColumn Visible = "False" DataField = "orders_itemno" SortExpression = "orders_itemno"> </asp: ButtonColumn>

<Asp: ButtonColumn Text = "orders_orderno" DataTextField = "orders_orderno" HeaderText = "Order No" CommandName = "orders_orderno"> </asp: ButtonColumn>
<Asp: ButtonColumn Text = "orders_itemno" DataTextField = "orders_itemno" HeaderText = "Item No" CommandName = "orders_itemno"> </asp: ButtonColumn>

<Asp: BoundColumn DataField = "orders_account" SortExpression = "orders_account" HeaderText = "Account"> </asp: BoundColumn>:

Instead of Bound Field try to use TemplateField

 

                            <asp:TemplateField>                                <ItemTemplate>                                    <asp:Button ID="btnClick" runat="server" Text="Click" />                                </ItemTemplate>                            </asp:TemplateField>

A:

When you use the buttoncolumn, I believe it fires the rowcommand event, so what you can do is hook onto the rowcommand event of the gridview, and you can inspect the GridViewCommandEventArgs event arguments as it has a property called CommandName which you can use to distinguish which button click was raised.

A:

Hi your can add two button in itemtemplate and handle its click event on code side

 <asp:TemplateField>
<ItemTemplate>
                                    <asp:Button ID="btnClick" runat="server" Text="Click" onclick="button1_click" />
<asp:Button ID="btnClick2" runat="server" Text="Click" onclick="button2_click" />
</ItemTemplate>
</asp:TemplateField>

 

A:

Thanks for the quick response, but this is not how I want to do things. (Dont want to display buttons in my grid-I want a link from the value being displayed .)

Eg.Orderno01|Item001| Account002 |...

A:

You can use HyperLink field to give link

<Asp: HyperLink id = "hypLink1" runat = "server" NavigationUrl = "Where U Want To Transfer" Text = '<% # Eval ("DataBaseFiledName") %>'/>

A:

Found it! Thanks to the help of jimmy
You can check this by simply using the e. CommandName in the DataGridCommandEventHandler. easy.

Thanks guys!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.