<asp:TemplateField ConvertEmptyStringToNull="True">
<ItemTemplate>
<asp:Label ID="lblpsaia" Visible='<%# !(bool) IsInEditMode %>'
runat="server" Text='<%# Eval("psaia") %>' />
<asp:TextBox ID="txtpsaia" ControlStyle-CssClass="wide"
Visible='<%# IsInEditMode %>'
runat="server" Text='<%# Eval("psaia") %>' />
</ItemTemplate>
</asp:TemplateField>
在此示例中,我可以动态设置标签和文本框的Text属性(在C#中)吗?
答案 0 :(得分:1)
尝试这样的事情。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblpsaia = (Label)e.Row.FindControl("lblpsaia");
lblpsaia.Text = "Sample Text Here";
TextBox txtpsaia = (TextBox)e.Row.FindControl("txtpsaia");
txtpsaia.Text = "Sample Text Here";
}
}