2017-10-16 61 views
0

我正试图用所选行的数据填充标签,但lm没有获胜。我已经尝试了超过5种以上的解决方案,但是没有一个能够正常工作。用选定的gridview行填充标签

下面是我的代码:

lblBookID.Text = grdLWAPBook.SelectedRow.Cells[0].ToString(); 
     lblStudNum.Text = grdLWAPBook.SelectedRow.Cells[1].ToString(); 
     lblLWAp.Text = grdLWAPBook.SelectedRow.Cells[2].ToString(); 
     lblDate.Text = grdLWAPBook.SelectedRow.Cells[3].ToString(); 
     lblTime.Text = grdLWAPBook.SelectedRow.Cells[4].ToString();enter code here 
+0

你这个代码得到什么行为?任何错误? –

+0

您订阅了哪个活动?尝试调试并使用Debug.WriteLine()在单击行时转储出单元格的值。 –

回答

0

假设your're尝试它的按钮单击事件中:

GridViewRow row = (GridViewRow)((Button)sender).NamingContainer; 

lblBookID.Text = row.Cells[0].ToString(); 
+0

System.Web.UI.WebControls.DataControlFieldCell ....这是标签现在填充的内容。我将您的代码更改为LinkBut​​ton,因为它是ASP.NET中的链接按钮 –