在 C# ListView 中的 EmptyDataTemplate 中的控制項
以及在 LayoutTemplate 中的控制項
取法稍略不同
// EmptyDataTemplate
if (ListView1.Items.Count == 0)
{
string text = ((TextBox) ListView1.Controls[0].FindControl("TextBox1")).Text;
}
// LayoutTemplate
else
{
string text = ((TextBox) ListView1.FindControl("TextBox1")).Text;
}
由於 EmptyDataTemplate 是 ListView 無資料才會動態產生
故可以用 ListView.Items.Count 來判別是否有資料
EmptyDataTemplate 在尋找控制項時必須先指定 Controls[0]
才可以找到 EmptyDataTemplate 中的控制項
全站熱搜