ASP.NET DetailsView 更改编辑诗句插入模式的字段显示
对于 ASP.NET,我使用 DetailsView 来插入和编辑记录。对于编辑模式,我不想显示主键字段,因为它不应该被更改。对于插入模式,我想显示主键字段,因为它不存在,并且用户可以通过 DropDownList 指定它,以确保他们选择唯一值。 TemplateField 在主键字段的 DetailsView 标记中使用(因此插入模式使用 DropDownList)。
我的问题是我无法让主键字段在编辑模式下不显示并在插入模式下显示。在标记中,我有:
<asp:TemplateField HeaderText="name" InsertVisible="True" Visible="True">
<InsertItemTemplate>
<asp:DropDownList ID="ddl2NonMembers" runat="server"
Width="155px"
Sourceless="sqlNonMembers"
DataTextField="name"
DataValueField="id_adm"
SelectedValue='<%# Bind("member_grp") %>'>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
使用 TemplateField Visible="True",HeaderText="name" 始终显示我不想要的编辑模式。使用 TemplateField Visible="False",该字段永远不会显示我不想要的插入模式。
如何实现插入诗句编辑模式所需的显示行为。我很乐意以编程方式更改某些属性,而不是依赖纯标记方法,但我无法找出解决方案。
请指教!
For ASP.NET, I'm using a DetailsView for insert and edit of a record. For edit mode I don't want to display the primary key field because it should not be changed. For insert mode, I want to display the primary key field because it doesn't exist and the user can specify it via a DropDownList that insures they will pick an unique value. A TemplateField is used in the DetailsView markup for the primary key field (hence the DropDownList for insert mode).
My problem is that I cannot get the primary key field to not display for edit mode and to display for insert mode. In the markup I have:
<asp:TemplateField HeaderText="name" InsertVisible="True" Visible="True">
<InsertItemTemplate>
<asp:DropDownList ID="ddl2NonMembers" runat="server"
Width="155px"
Sourceless="sqlNonMembers"
DataTextField="name"
DataValueField="id_adm"
SelectedValue='<%# Bind("member_grp") %>'>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
With the TemplateField Visible="True", the HeaderText="name" always displays which I don't want for edit mode. With the TemplateField Visible="False", the field never displays which I don't want for insert mode.
How can I achieve the display behavior I want for insert verses edit mode. I'm fine with changing some property programmatically rather than relying an a pure markup approach, but I can't figure out the solution.
Please advise!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以测试详细信息查看模式并查看它是否处于“编辑”模式。然后,您可以通过编程方式隐藏 DropDownList。
此外,您可以隐藏整个列,但您需要知道该列的索引。假设列索引为 #5,您可以执行以下操作:
最后,您可以在代码隐藏中创建一个函数,该函数检查 DetailsView 的当前值并将其分配给模板字段的 Visible 属性:
在模板字段内:
you can test the Details View Mode and see if it's in -Edit- mode. You can then hide the DropDownList programmatically.
Also, you can hide the entire column, but you'll need to know the index of that column. Assuming column index is #5 you can do something like:
And finally, you can create a function in Code-Behind which checks the current value of the DetailsView and assign it to the Visible property of your Template field:
And inside your Template Field: