【发布时间】:2013-10-25 07:28:56
【问题描述】:
我有疑问
以下这些类型的标签文本声明有什么不同?
<asp:Label ID="lbl2" **Text="Name"** runat="server"></asp:Label>
和
<asp:Label ID="lbl2" runat="server"**>Name</**asp:Label>
我直接在文本属性Text="Name" 中提供了文本,并在标签字段> Name </ 的中心提供了文本
我的gridview控件上有更多标签,我想在编辑网格时获取标签文本值,我正在使用查找控件来获取标签值
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Label xx = GridView1.Rows[e.NewEditIndex].FindControl("lbl2") as Label;
Label yy = GridView1.Rows[e.NewEditIndex].FindControl("lbl2") as Label;
txtName.Text = xx.Text;
txtAge.Text = yy.Text;
}
这是我的网格视图代码
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lbl1" Text='<%# Eval("StudentName") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
如果我将 Eval 值放在标签 Text 属性中,它工作正常,但如果我在标签中心提供 eval 值,例如 (<asp:Label ID="lbl1" runat="server"><%# Eval("StudentName") %></asp:Label>),则查找控件没有返回值,它返回空("") 。为什么?
编辑:
但是,如果我在 gridview 之外设置标签文本,两种方式都可以正常工作(如果以这两种方式设置文本,lblid.text 会给出正确的)!只有我在 gridview 的标签中遇到了问题!
【问题讨论】: