【问题标题】:No mapping exists from object type System.Web.UI.WebControls.GridViewRow to a known managed provider native type不存在从对象类型 System.Web.UI.WebControls.GridViewRow 到已知托管提供程序本机类型的映射
【发布时间】:2014-01-21 00:35:17
【问题描述】:

我想做一个gridview,当我选择一行时,它的值将填充到另一个gridview和文本框,但我遇到了上面的错误。当我单击 GridView2 中的行时,什么都没有发生,并且 sqladapter 中发生错误。请帮我修复此代码..

这是我的代码: c#

protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(conn);
    SqlCommand com = new SqlCommand("SELECT MRPNo, MRPType, MRPDate FROM MRP WHERE MRPNo = @mrpno",con);
    com.Parameters.Add("@mrpno", GridView2.SelectedRow);
    DataTable dt = new DataTable();
    SqlDataAdapter sda = new SqlDataAdapter(com);
    sda.Fill(dt);
    DataRow row = dt.Rows[0];
    txtMRPNo.Text = row["MRPNo"].ToString();
    txtMRPDate.Text = row["MRPType"].ToString();
    txtMRPDate.Text = row["MRPDate"].ToString();
    GridView3.DataBind();
    GridView1.DataBind();
}

protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
    LinkButton selectButton = new LinkButton()
    {
        CommandName = "Select",
        Text = e.Row.Cells[0].Text,
    };
    e.Row.Cells[0].Controls.Add(selectButton);
}

protected void GridView2_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
            e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
            e.Row.ToolTip = "Click to select row";
            e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView2, "Select$" + e.Row.RowIndex);
        }
    }
}

【问题讨论】:

    标签: c# asp.net sql gridview


    【解决方案1】:

    您不能使用 GridView2.SelectedRow 作为 Parameters.Add() 的输入。请参考 MSDN (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrow(v=vs.110).aspx) 你会明白为什么。

    【讨论】:

      猜你喜欢
      • 2015-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多