当我更新网格中的一行时,我有一个带有书籍详细信息的网格,因此无法转换类型为#System; Web.UI.WebControls.TextBox'键入' System.IConvertible'错误。请帮我解决这个错误。价格列是十进制数据类型。
protected void grdBookDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
BookDetailsBEL.BookId = Convert.ToInt32(grdBookDetails.DataKeys[e.RowIndex].Value);
BookDetailsBEL.BookName = ((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtEditBookName"))).ToString();
BookDetailsBEL.Author = ((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtEditAuthor"))).ToString();
BookDetailsBEL.Publisher = ((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtEditPublisher"))).ToString();
BookDetailsBEL.Price = Convert.ToDecimal((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtEditPrice")));
e.Cancel = true;
grdBookDetails.EditIndex = -1;
GetBookDetails();
}
答案 0 :(得分:0)
您必须使用.Text
属性
protected void grdBookDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
BookDetailsBEL.BookId = Convert.ToInt32(grdBookDetails.DataKeys[e.RowIndex].Value);
BookDetailsBEL.BookName = ((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtEditBookName"))).Text.ToString();
BookDetailsBEL.Author = ((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtEditAuthor"))).Text.ToString();
BookDetailsBEL.Publisher = ((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtEditPublisher"))).Text.ToString();
BookDetailsBEL.Price = Convert.ToDecimal(((TextBox)(grdBookDetails.Rows[e.RowIndex].FindControl("txtEditPrice"))).Text.ToString());
e.Cancel = true;
grdBookDetails.EditIndex = -1;
GetBookDetails();
}