【发布时间】:2012-07-04 06:57:10
【问题描述】:
我在尝试使用参数 CommandName = "x" 触发 GridView 中的按钮时遇到问题,我尝试在 GridView1_RowCommand 事件中访问我的 "If" 但由于某种原因我不能,如果你能帮助我不胜感激。
这是我的 .aspx 部分
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" CellPadding="4"
EnableModelValidation="True" ForeColor="#333333" GridLines="None"
Height="193px" Width="968px" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SOURCE1" onrowcommand="GridView1_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button Text = "Seleccionar" runat="server" CommandName="X" CommandArgument='<%# Container.DataItemIndex %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="IDEmpresa" HeaderText="IDEmpresa"
SortExpression="IDEmpresa" />
</Columns>
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
这是我的 C# 代码:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "X")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
Label1.Text = "WOW It reached out";
}
}
我按照 ASP.net 页面的说明进行操作,我对 .net 相当陌生(我不知道 UpdatePanel 是否与它有关)
【问题讨论】:
-
你是否禁用了视图状态?
标签: asp.net events button command arguments