将面板或标签控件动态添加到数据网格
基于对 ItemTemplate 内现有面板/标签(使用 Column1)的测试值,我想在同一 ItemTemplate 内添加另一个面板/标签(显示 Column2)。
这是在一个自定义控件 (.ascx) 内,我想根据它(或另一个面板)是否具有特定值来控制一个特定
的添加。如果不是,我不希望创建
(不应在运行时生成
)。如果是,我想在里面生成
示例<asp:DataGrid><Columns><ItemTemplate>
:假设我们按预期获得 Column2 值,我只想在该值不为“0”时呈现该值,如果不是,我不想在给定的
If(Column2!='0')
//Adding some condition for Column1 ...
Create the `<div>` tag i.e Add the `<asp:Panel>`
我应该如何调用这段代码?
这意味着,在某些情况下生成的 html 将具有附加的 div/span 标签,而在其他情况下不应生成这些标签。 可以避免使用 Javascript 来完成此操作吗?
Based on testing values of an existing panel/label inside an ItemTemplate (uses Column1), I want to add another panel/label inside the same ItemTemplate (displays Column2).
This is inside a custom control (.ascx) that I want to control the addition of one particular <asp:Panel>
based on if it (or another panel) has a particular value or not. If not, I don't want the <asp:Panel>
to be created (shouldn't generate the <div>
at runtime). If yes, I want to generate the <asp:Panel>
inside
the
<asp:DataGrid><Columns><ItemTemplate>
Example: Assuming we are getting Column2 value as expected, I want to render this value only if it's not '0', if not I don't want to CREATE the extra tag inside the given <ItemTemplate>
. I will control when it's rendered based on another tag.
If(Column2!='0')
//Adding some condition for Column1 ...
Create the `<div>` tag i.e Add the `<asp:Panel>`
How should I call this code also?
That means, the html generated will have the additional div/span tags on some cases and should not have the tags generated on other cases.
Can this be done avoiding Javascript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用
控件将该控件放置在 .ascx 中的某个位置,例如:One could use the
<asp:PlaceHolder>
control to place the control at a certain place in the .ascx, say:<asp:PlaceHolder id="placeHere" runat="server />
and determine based on the other control whether this should be added.Example: