开发者

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

<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开发者_Python百科="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

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.

The GridView SeletedIndexChanged event is using to capture selection changing only. That means, if you pressed a command row on an already selected row, the SelectedIndexChanged is not going to fired.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜