使用row命令分页

问题描述 投票:0回答:2

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

Here's the image of the problem

如果我使用

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.LinkButton”类型。

c# gridview pagination rowcommand
2个回答
0
投票

尝试将

LinkButton
更改为
Control
:

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

或者使用这个:

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

或者这个:

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

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();
    } 
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.