问题描述
我试图让 GridView控件
的选定行了,我知道我应该能够得到一个基于 OnSelectedIndexChanged信息
事件。每当我点击该行,该事件不火。
I am trying to get the selected row of the GridView
, and I know that I should be able to get that information based on the OnSelectedIndexChanged
event. Whenever I click on the row, the event does not fire.
<asp:GridView ID="GridView1" runat="server" GridLines="None"
Width="930px" CellPadding="4" ForeColor="#333333"
onselectedindexchanged="GridView1_SelectedIndexChanged2">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
protected void GridView1_SelectedIndexChanged2(object sender, EventArgs e)
{
//string company = GridView1.SelectedRow.Cells[0].Text;
Response.Redirect("Client_View.aspx", false);
}
任何帮助,这将是AP preciated。没有code,我可以看到它的复位参照另一个事件,我可以看到。
Any help with this would be appreciated. There is no code that I can see that resets its reference to another event, that I can see.
推荐答案
如果你只是点击了 GridView控件
行,不会触发事件。你必须有某种行中按钮的点击,这将触发 RowCommand
事件,以及在的SelectedIndexChanged
事件(如果你单击该行尚未选择,当然)。这不是完全像Windows窗体DataGridView =)
If you are just clicking on the row in the GridView
, that will not fire the event. You have to have some kind of button in the row to click on, which will fire the RowCommand
event, as well as the SelectedIndexChanged
event (if the row you click is not already selected, of course). It's not exactly like the Windows Forms DataGridView =)
去触发事件的最简单方法,就是这个属性添加到您的 GridView控件
标记:
The easiest way to get the event to fire, is to add this attribute to your GridView
markup:
AutoGenerateSelectButton="True"
这将创建一个选择的LinkButton
,这将在code-火 Gridview1_SelectedIndexChanged2
事件后面当你点击它。
This creates a "Select" LinkButton
, which will fire the Gridview1_SelectedIndexChanged2
event in your code-behind when you click it.
编辑:只是为了澄清,这是你需要添加属性:
Just to clarify, this is where you need to add that attribute:
<asp:GridView ID="GridView1" runat="server" GridLines="None"
Width="930px" CellPadding="4" ForeColor="#333333"
onselectedindexchanged="GridView1_SelectedIndexChanged2"
AutoGenerateSelectButton="True" >
这篇关于GridView控件OnSelectedIndexChanged事件不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!