【发布时间】:2014-05-15 19:00:51
【问题描述】:
我将我的值从 gridview 按行传递到不同的页面。数据库中 gridview 的表如下:
Create table Task
(
TaskId int Identity(1,1),
Title varchar(100),
Body varchar(500),
Reward decimal(4,2),
TimeAllotted int,
PosterName varchar(100)
)
详情页面的代码如下:
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;
我该如何纠正这个问题?
【问题讨论】:
标签: c# asp.net sql-server gridview