[英]Getting the text content of a linkbutton control
我在gridview中有linkbutton控件:
我试图从这些控件中获取文本:
protected void hoursReportGridView_OnRowDataBound(Object sender, GridViewRowEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.Row.Cells[4].Text);
}
结果如下:
Task
我在做什么错了,我该如何理解教科书?
您可以使用FindControl
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton btn= ((LinkButton )e.Row.FindControl("YourControlId"));
var text = btn.Text;
//Here you have btn object
}
您是否尝试过以下类似方法?
if(e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton btn = (LinkButton)e.Row.FindControl("btn");
}
您需要跳过标题行,而仅处理数据行,如下所示:
protected void hoursReportGridView_OnRowDataBound(Object sender, GridViewRowEventArgs e)
{
// Ignore all other rows types (header, footer, etc.) except data rows
if(e.Row.RowType == DataControlRowType.DataRow)
{
System.Diagnostics.Debug.WriteLine(e.Row.Cells[4].Text);
}
}
有关网格视图中数据行类型的更多信息,请阅读GridViewRow.RowType属性 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.