0

我有一个带有“选择”行和分页的gridview。当我尝试更改分页站点时出现错误。

这是问题的图像

如果我使用语句,我可以摆脱这个问题,If()但是我的选择事件将不起作用。

/*************Acitivate "Search" column for every row in gridview******************/
    protected void gwActivity_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        /*if (e.CommandName.ToString() == "Select")*/

        {
            GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);           
            txtActivity.Text = row.Cells[2].Text;
            ddlStatus.SelectedValue = row.Cells[4].Text;
            ddlResponsible.SelectedValue = row.Cells[5].Text;
            ddlCategory.SelectedValue = row.Cells[6].Text;
            ddlPriority.SelectedValue = row.Cells[7].Text;
            ddlSize.SelectedValue = row.Cells[8].Text;
            ddlSystem.SelectedValue = row.Cells[9].Text;
            ddlChange_Requestor.SelectedValue = row.Cells[10].Text;
            txtComment.Text = row.Cells[11].Text;


        }

    }

错误:

App_Web_rsb5hpia.dll 中出现“System.InvalidCastException”类型的异常,但未在用户代码中处理其他信息:无法将“System.Web.UI.WebControls.GridView”类型的对象转换为“System.Web.UI”类型。 WebControls.LinkBut​​ton'。

4

2 回答 2

0

尝试将其更改LinkButtonControl

GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);

或者使用这个:

GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;

或者这个:

GridViewRow row = ((e.CommandSource as Control).NamingContainer as GridViewRow);
于 2018-04-03T13:55:24.840 回答
0
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = int.Parse(((Label)gvListadoActividades.Rows[e.RowIndex].FindControl("MyId")).Text);
        this.DeletedMyid(id);
        this.GridView1.EditIndex = -1;
        this.LoadMyData();
    } 
于 2019-11-08T16:46:34.420 回答