Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.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
ASP.net Gridview事件未触发,即分页或选择按钮,但会导致回发_Asp.net_Gridview_Data Binding - Fatal编程技术网

ASP.net Gridview事件未触发,即分页或选择按钮,但会导致回发

ASP.net Gridview事件未触发,即分页或选择按钮,但会导致回发,asp.net,gridview,data-binding,Asp.net,Gridview,Data Binding,标记和编码 单击搜索按钮后,我将绑定到gridview。 它工作了一段时间,但后来它停止了,我不知道我做了什么来打破它。 我没有在页面加载上绑定任何内容 我最初试图通过Gridview实现Ajax protected void gvParticipantResults_RowCommand(object sender, GridViewCommandEventArgs e) { string strCommand = e.CommandName.ToString(); if (s

标记和编码 单击搜索按钮后,我将绑定到gridview。 它工作了一段时间,但后来它停止了,我不知道我做了什么来打破它。 我没有在页面加载上绑定任何内容 我最初试图通过Gridview实现Ajax

protected void gvParticipantResults_RowCommand(object sender, GridViewCommandEventArgs e)
{
    string strCommand = e.CommandName.ToString();
    if (strCommand == "Select")
    {
        int row = Convert.ToInt32(e.CommandArgument);
        // setting the selected row to yellow to show whome they are working with
        gvParticipantResults.Rows[row].BackColor = Color.Yellow;
        // getting the participant ID
        ParticipantID = Convert.ToInt32(gvParticipantResults.DataKeys[row].Value);
    }
    else if (strCommand == "XXXX")
    {
        strCommand = "SELECT";
    }
}

protected void gvParticipantResults_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    // Set the index of the new display page.  
    gvParticipantResults.PageIndex = e.NewPageIndex;
    // Rebind the GridView control to  
    // show data in the new page. 
    // BindGridView();
}

<asp:GridView ID="gvParticipantResults" runat="server" Height="125px" 
              BorderColor="Black" DataKeyNames="ParticipantID" 
              Width="200px" CellPadding="4" GridLines="Both"
              onrowcommand="gvParticipantResults_RowCommand" 
              onselectedindexchanged="btnSearchParticipant_Click" 
              ForeColor="#333333" AutoGenerateColumns="False" 
              AllowPaging="True" PageSize = "10"
              onpageindexchanging="gvParticipantResults_PageIndexChanging">
    <PagerSettings NextPageText="Next &amp;gt;" />
    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
    <Columns>
        <asp:ButtonField Text="Select" CommandName="Select" ButtonType="Button" CausesValidation = "false" />
        <asp:BoundField DataField="ParticipantID" HeaderText="ParticipantID" SortExpression="ParticipantID"  Visible = "false" />
        <asp:BoundField DataField="IsActive" HeaderText="IsActive" SortExpression="IsActive" />
        <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
        <asp:BoundField DataField="MiddleName" HeaderText="MiddleName" SortExpression="MiddleName" />
        <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
        <asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
        <asp:BoundField DataField="DateOfBirth" HeaderText="DateOfBirth" SortExpression="DateOfBirth" />
        <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />                            
    </Columns>
    <FooterStyle BackColor="#990000" ForeColor="White" Font-Bold="True" />
    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" /> 
</asp:GridView>
protectedvoid gvParticipantResults_RowCommand(对象发送方,GridViewCommandEventArgs e)
{
字符串strCommand=e.CommandName.ToString();
如果(strCommand==“选择”)
{
int row=Convert.ToInt32(e.CommandArgument);
//将所选行设置为黄色,以显示正在处理的对象
gvParticipantResults.Rows[row].BackColor=Color.Yellow;
//获取参与者ID
ParticipantID=Convert.ToInt32(gvParticipantResults.DataKeys[row].Value);
}
否则如果(strCommand==“XXXX”)
{
strCommand=“选择”;
}
}
受保护的void gvParticipantResults_PageIndexChanging(对象发送方,GridViewPageEventArgs e)
{
//设置新显示页面的索引。
gvParticipantResults.PageIndex=e.NewPageIndex;
//将GridView控件重新绑定到
//在新页面中显示数据。
//BindGridView();
}

您的代码正在运行。然而,以下是我的发现

GridView的选中索引更改后的已附加到BTN搜索参与者。\u单击。我不知道其背后的原因

onselectedindexchanged="btnSearchParticipant_Click"

因此,无论何时启动gvParticipatentResults\u RowCommand,都会启动bTNSearchParticipatent\u Click

哪些事件不起作用?页面加载看起来像什么?受保护的无效页面加载(对象发送方,事件参数e){if(!IsPostBack){rblContentType.Items[0].Selected=true;}否则{}}onrow命令不起作用,onselectedIndex也没有更改,onpageIndexchanging我认为它们区分大小写。请改为尝试以下操作:OnRowCommand、OnSelectedIndexChanged和OnPageIndexChangingok,我从标记中删除了OnSelectedIndexChanged=“btnSearchParticipant\u Click”,但它仍然没有命中其他两个事件。请删除AJAX进行调试。还要确保页面上的
AutoEventWireup=“true”
如下-