【发布时间】:2016-07-18 11:25:53
【问题描述】:
我一直在研究 ASPX webform 应用程序,其中我有一个带有文本框控件的 gridview。我的问题是,我只想在此文本框具有绑定属性时为其设置文本值。
<asp:GridView ID="grvShowRecord" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Value">
<ItemTemplate>
-- Something like this, i don't know how to write in ASPX, but in Razor it will be something like
@{
if(Bind("txtValue")!=null) -- IF gridview has Bind("txtValue") property then show textbox else show label
{
<asp:TextBox ID="txtValue" runat="server" Text='<%# Bind("txtValue") %>' ></asp:TextBox>
}
else
{
<asp:Label ID="lblValue" runat="server" Text="0" ></asp:TextBox>
}
}
</ItemTemplate>
</asp:TemplateField>
</Columns>
注意:最初在页面加载时绑定 Gridview 时,我没有使用任何 Bind 属性,但后来我设置了这个 Bind 属性,然后再次绑定 gridview。 提前致谢
【问题讨论】:
标签: c# asp.net gridview aspxgridview itemtemplate