我有一个Gridview内的标签。我想在静态方法中使用标签值。这是我的代码:
public static string seat(string SeatNum)
{
if (HttpContext.Current != null)
{
Page page = (Page)HttpContext.Current.Handler;
Label lblSeatNum = (Label)page.FindControl("lblSeatNo");
Label lblfare = (Label)page.FindControl("lblTotfare");
GridView grd = (GridView)page.FindControl("rptrbus");
lblSeatNum.Text = SeatNum.ToString();
Label lblgrdfare = (Label)grd.FindControl("lbFare");
lblfare.Text = lblgrdfare.Text;
}
int dt=0;
return dt.ToString();
}
答案 0 :(得分:0)
以下代码如何:
Label lblSeatNum = (Label)page.FindControl("lblSeatNo");
if(lblSeatNum != null)
string text = lblSeatNum .Text;