C#:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType != DataControlRowType.DataRow) // 非資料行, 離開
return;
//單筆, 取得指定名稱Label物件, 若Text="n/a", 將Text改為空白
Label lblGvptz_zoom = e.Row.FindControl("lblGvptz_zoom") as Label;
if (lblGvptz_zoom.Text.Equals("n/a"))
lblGvptz_zoom.Text = "";
//多筆迴圈, 取得Row下所以Cells中的Label物件, 若Text="n/a", 將Text改為空白
foreach (TableCell cl in e.Row.Cells)
{
foreach (object ctrl in cl.Controls)
{
if (ctrl is System.Web.UI.WebControls.Label) //判斷ctrl是否為Label物件
{
Label lblctrl = (Label)ctrl;
if (lblctrl.Text.Equals("n/a"))
lblctrl.Text = "";
}
}
}
}
catch (Exception)
{
throw;
}
}
沒有留言:
張貼留言