簡體   English   中英

從對象類型System.Web.UI.WebControls.GridViewRow到已知托管提供程序本機類型的映射不存在

[英]No mapping exists from object type System.Web.UI.WebControls.GridViewRow to a known managed provider native type

我想做一個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);
        }
    }
}

您不能將GridView2.SelectedRow用作Parameters.Add()的輸入。 請參考MSDN( http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrow ( v=vs.110 ) .aspx ),您將看到原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM