Using two asp:ButtonColumns in one row of datagrid

來源:互聯網
上載者:User

來源: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>A:

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!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.