如何在静态方法中获取Gridview内部的标签值

时间:2017-01-12 11:17:37

标签: asp.net gridview

我有一个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();
}

1 个答案:

答案 0 :(得分:0)

以下代码如何:

Label lblSeatNum = (Label)page.FindControl("lblSeatNo");
if(lblSeatNum  != null)
     string text = lblSeatNum .Text;