我正在将我的值从gridview传递到不同的页面rowwise wise.The数据库中的gridview表如下所示:不能隐式地将类型'字符串'转换为'System.Web.UI.WebControls.Label'
Create table Task
(
TaskId int Identity(1,1),
Title varchar(100),
Body varchar(500),
Reward decimal(4,2),
TimeAllotted int,
PosterName varchar(100)
)
代码-behind的详细信息页面,如下:
protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.PreviousPage != null)
{
int rowIndex = int.Parse(Request.QueryString["RowIndex"]);
GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
GridViewRow row = GridView1.Rows[rowIndex];
lblTaskId.Text = row.Cells[0].Text;
lblTitle.Text = row.Cells[1].Text;
lblBody.Text = row.Cells[2].Text;
lblReward.Text = row.Cells[3].Text;
lblTimeAllotted = row.Cells[4].Text;
lblPosterName = row.Cells[5].Text;
}
}
它显示为所需的一切,但是当我在GridView的特定行上的“查看任务”点击,我得到一个异常无法将类型'字符串'隐式转换为'System.Web.UI.WebControls.Label'。最后两个异常发生例如
lblTimeAllotted = row.Cells[4].Text;
lblPosterName = row.Cells[5].Text;
有人知道为什么吗?我怎样才能纠正这一点?请帮忙。
愚蠢的错误。非常感谢你指出。 – Mash
它发生在每个人身上!乐意效劳! – logixologist