Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Gridview链接按钮未触发RowCommand_C#_Asp.net_Gridview - Fatal编程技术网

C# Gridview链接按钮未触发RowCommand

C# Gridview链接按钮未触发RowCommand,c#,asp.net,gridview,C#,Asp.net,Gridview,我正在设计一个搜索页面,如果点击查看/编辑链接按钮,另一个页面将加载更多关于主题的信息;单击按钮时,不会引发Gridview的RowCommand事件。Gridview是基于搜索词动态构建的,并通过SQLDataSource与数据库进行比较。下面是Gridview的html <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RID" DataSourceID="Repo

我正在设计一个搜索页面,如果点击查看/编辑链接按钮,另一个页面将加载更多关于主题的信息;单击按钮时,不会引发Gridview的RowCommand事件。Gridview是基于搜索词动态构建的,并通过SQLDataSource与数据库进行比较。下面是Gridview的html

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RID" DataSourceID="Report_System" CellPadding="4" ForeColor="#333333" GridLines="None" OnDataBound="GridView1_DataBound" Width="739px" OnRowCommand="GridView1_RowCommand">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:BoundField DataField="RID" HeaderText="Report ID" InsertVisible="False" ReadOnly="True" SortExpression="RID" />
            <asp:BoundField DataField="Rdate" HeaderText="Report Date" SortExpression="Rdate" />
            <asp:BoundField DataField="Rtype" HeaderText="Type" SortExpression="Rtype" />
            <asp:BoundField DataField="OID" HeaderText="Officer ID" SortExpression="OID" />
            <asp:BoundField DataField="Ofirstname" HeaderText="Officer" SortExpression="Ofirstname" />
            <asp:BoundField DataField="Pname" HeaderText="Student Reportee" SortExpression="Pname" />
            <asp:ButtonField CommandName="View/Edit" Text="View/Edit" />
        </Columns>
        <EditRowStyle BackColor="#7C6F57" />
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#E3EAEB" />
        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F8FAFA" />
        <SortedAscendingHeaderStyle BackColor="#246B61" />
        <SortedDescendingCellStyle BackColor="#D4DFE1" />
        <SortedDescendingHeaderStyle BackColor="#15524A" />
    </asp:GridView>

我已确保ViewState已启用,onrow命令位于正确的位置,并且我的PageLoad事件为空。除此之外,我找不到任何论坛帖子来帮助我。有什么想法吗?

尝试在
GridView1\u RowCommand
中添加一个带有
if
语句的
CommandName
检查,如下所示

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      if(e.CommandName == "View/Edit")
      {
        //get row index
        int row = Convert.ToInt32(e.CommandArgument);

        errorLabel.Text = row.ToString();
      }
    }

这个问题我已经争论过很多次了,但是我已经太长时间不记得我尝试过的所有事情以及为什么各种选择都不起作用了。但是,我可以告诉您我现在做什么,这对我来说很有用:添加OnRowEditing事件而不是OnRowCommand。编辑:哦,将命令名改为“编辑”而不是“查看/编辑”。尝试将转换为TemplateField。更改事件无效,因此我尝试用每个事件对其进行测试,唯一触发的事件是PreRender事件,这是显而易见的。当我按下按钮时,没有任何东西被触发,这告诉我还有其他问题。我还没有完全尝试TemplateField的想法,但奇怪的是根本没有触发任何事件。所以你找到了解决方案?如果能与社区分享,那就太好了。我的链接按钮有问题。Add CausesValidation=“false”
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      if(e.CommandName == "View/Edit")
      {
        //get row index
        int row = Convert.ToInt32(e.CommandArgument);

        errorLabel.Text = row.ToString();
      }
    }