[英]No mapping exists from object type System.Web.UI.WebControls.GridViewRow to a known managed provider native type
I want to make a gridview that when I select a row, its values will be populated to another gridview and text boxes, but I am encountering the error above. 我想做一个gridview,当我选择一行时,它的值将被填充到另一个gridview和文本框中,但是遇到了上面的错误。 When I click the row in the GridView2, nothing is happening and an error in the sqladapter occurs.
当我单击GridView2中的行时,什么也没有发生,并且sqladapter中发生错误。 Please help me to fix this code..
请帮助我修复此代码。
Here is my code: c# 这是我的代码: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);
}
}
}
You can not use GridView2.SelectedRow as an input to Parameters.Add(). 您不能将GridView2.SelectedRow用作Parameters.Add()的输入。 Please refer to MSDN ( http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrow(v=vs.110).aspx ) and you will see why.
请参考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.