簡體   English   中英

從后面的代碼中兩個按鈕都為commandname =“ Select”時,如何檢測哪個按鈕列用戶單擊了?

[英]how can i detect which buttoncolumn user clicked when both button are commandname=“Select” from code behind?

我在這樣的GridView有2個選擇Button控件

<asp:datagrid style="Z-INDEX: 0" id="DataGrid1" runat="server" Width="936px"      
HorizontalAlign="Justify" CellPadding="5" AutoGenerateColumns="False" 
AllowCustomPaging="True" AllowSorting="True">

<asp:ButtonColumn Text="Button 1" CommandName="Select">
<HeaderStyle Width="5%"></HeaderStyle>
</asp:ButtonColumn>

<asp:ButtonColumn Text="Button 2" CommandName="Select">
<HeaderStyle Width="5%"></HeaderStyle>
</asp:ButtonColumn>

</asp:datagrid>

DataGrid1_SelectedIndexChanged后面的代碼中,如何檢測用戶單擊了哪個按鈕

private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
    if(//user click button 1) {}
    else // user clicked button 2 {}
}

謝謝你的回答

要像您的情況一樣響應行命令,您需要處理GridView RowCommand事件。

GridView SeletedIndexChanged事件僅用於捕獲選擇更改。 這意味着,如果在已選擇的行上按下命令行,則不會觸發SelectedIndexChanged

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM