2015-02-24 56 views
0
<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> 

我可以在此示例中動態地(在C#中)設置標籤和文本框的Text屬性?動態設置文本框和標籤在GridView中的文本屬性

+0

你是什麼意思「動態」?在Data_RowBound期間?還是從客戶端? – 2015-02-24 19:56:06

+0

在Data_RowBound期間。 – 2015-02-24 19:57:09

回答

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"; 
    } 
}