如何将网格视图中的单元格设置为下拉菜单
如何将网格中的单个单元格设置为下拉菜单。我有一个可编辑的网格,其中所有行都是可编辑的,除了单独的两行应该可以从下拉列表中选择。我们怎样才能实现它呢?我什至无法开始如何进行。有什么想法吗?
<asp:GridView AutoGenerateColumns="false" PageSize="300" ID="gvService"
runat="server" GridLines="None" BorderWidth="1" BorderColor="Brown" AlternatingRowStyle-BackColor="Cyan"
HeaderStyle-BackColor="ActiveCaption" ShowFooter="true">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Classic</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblClassic" runat="server" Text='<%# Eval("Classic") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
ABC</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblA" Visible='<%# ! IsInEditMode %>' runat="server" Text='<%# Eval("ABC") %>' />
<asp:TextBox ID="txtA" Visible='<%# IsInEditMode %>' runat="server" Text='<%#Eval("ABC")%>'
MaxLength="3" Columns="3">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
How to make a single cell in a grid to a dropdown. I have a editable grid in which all the rows are editable except two rows alone should be selectable from a dropdown. How can we achieve it? I could not start even how to proceed. Any ideas?
<asp:GridView AutoGenerateColumns="false" PageSize="300" ID="gvService"
runat="server" GridLines="None" BorderWidth="1" BorderColor="Brown" AlternatingRowStyle-BackColor="Cyan"
HeaderStyle-BackColor="ActiveCaption" ShowFooter="true">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Classic</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblClassic" runat="server" Text='<%# Eval("Classic") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
ABC</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblA" Visible='<%# ! IsInEditMode %>' runat="server" Text='<%# Eval("ABC") %>' />
<asp:TextBox ID="txtA" Visible='<%# IsInEditMode %>' runat="server" Text='<%#Eval("ABC")%>'
MaxLength="3" Columns="3">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
准确理解您的要求有点困难,但您可以添加另一个带有下拉列表的字段,例如:
如果您想显式地将数据绑定到它,您可以这样做:
It's a little difficult to understand exactly what you're asking for, but you can just add another field with a dropdown in it like:
And if you want to bind data to it explicitly you can do:
快速答案是...在gridview上编辑您的模板..它应该有一个下拉菜单..在该下拉菜单中您会找到“编辑项目模板”,您可以在那里粘贴您想要的任何控件..并且在视图中它应该只是文本或文本框,无论您使用什么。
有关模板字段的更多信息.. http://msdn.microsoft.com/en -us/library/aa479353.aspx
quick answer is... on the gridview edit your templates.. it should have a drop down.. in that drop down you will find "edit item template" you would stick whatever control you want there.. and in the view it should be just text or a textbox whatever you with.
little mor einfo on template fields.. http://msdn.microsoft.com/en-us/library/aa479353.aspx