简体   繁体   English

从后面的代码中两个按钮都为commandname =“ Select”时,如何检测哪个按钮列用户单击了?

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

i have 2 select Button controls in a GridView like this 我在这样的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>

In code behind in DataGrid1_SelectedIndexChanged how can i detect which button user has clicked DataGrid1_SelectedIndexChanged后面的代码中,如何检测用户单击了哪个按钮

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

thank for your answer 谢谢你的回答

To response to row commands as in your case, you need to handle GridView RowCommand event. 要像您的情况一样响应行命令,您需要处理GridView RowCommand事件。

The GridView SeletedIndexChanged event is using to capture selection changing only. GridView SeletedIndexChanged事件仅用于捕获选择更改。 That means, if you pressed a command row on an already selected row, the SelectedIndexChanged is not going to fired. 这意味着,如果在已选择的行上按下命令行,则不会触发SelectedIndexChanged

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测代码背后点击了哪个按钮? - How to detect which button was clicked in code behind? 当从后面的代码中单击按钮时,检查Dataitemtemplate devexpress gridview内部的复选框状态 - checking checkbox state which is inside Dataitemtemplate devexpress gridview when button is clicked from code behind 我如何从后面的代码访问按钮 - How can I get access to the button from code behind 单击后退按钮时如何从代码后面插入Javascript? (asp.net) - How to inject Javascript from code behind when back button is clicked? (asp.net) 按钮CommandName代码 - Button CommandName code 在文件后面的代码中检测到更新时,如何使用jquery显示更新? - How can I use jquery to display updates when I detect them in my code behind file? 关于回发,如何检查后面的代码中哪个html按钮导致回发 - On postback, how can I check which html button cause postback in code behind 单击按钮时用于运行代码隐藏代码的Javascript - Javascript for running code-behind code when a button is clicked 如何检测单击了哪个按钮,如果单击了两个,则调用该方法? - How to detect which button is clicked and if two are clicked then call the method? 当我单击按钮时,如何获取我在后面的代码中创建的 gridview 的值 - how can i get values of gridview that i created in code behind when i click button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM