Gridview标题自定义问题
如果我们向gridview
添加客户标题,它会添加额外的行吗?
目前,我有一个包含 4
列的 gridview
,当我添加自定义标题 gridview
时,它包含 5
行。
我的代码看起来像这样...
<asp:TemplateField HeaderText="" ItemStyle-Width="4%" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:DropDownList ID="Select" runat="server">
<asp:ListItem>Country</asp:ListItem>
<asp:ListItem>Region</asp:ListItem>
<asp:ListItem>Title</asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-Width="4%" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:HiddenField ID="Id" Value='<%#Eval("id")%>' runat="server" />
<asp:Literal ID="ltrImage" runat="server"></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
以及其他三个 TemplateFields
...
以这种方式添加标头有任何问题吗?还有其他方法可以添加客户标题而不出现此问题吗? 我想要的输出应该是这样的
Search Result Search By (Dropdownlist)
Data column1 Data column2 Data column3 Data column4
我现在得到的是
Sort By (Dropdownlist)
Data column1 Data column2 Data column3 Data column4
如果有想法有人可以帮忙吗? 提前致谢
If we add a customer header to the gridview
, will it add extra row?
Currently I have a gridview
with four
columns and, when I add a custom header gridview
coming with a five
rows.
My code looks like this...
<asp:TemplateField HeaderText="" ItemStyle-Width="4%" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:DropDownList ID="Select" runat="server">
<asp:ListItem>Country</asp:ListItem>
<asp:ListItem>Region</asp:ListItem>
<asp:ListItem>Title</asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-Width="4%" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:HiddenField ID="Id" Value='<%#Eval("id")%>' runat="server" />
<asp:Literal ID="ltrImage" runat="server"></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
and three other TemplateFields
...
Is there any problem of adding header this way? Any other way to add customer header without having this issue?
My desired output should look like this
Search Result Search By (Dropdownlist)
Data column1 Data column2 Data column3 Data column4
The one I am getting now is
Sort By (Dropdownlist)
Data column1 Data column2 Data column3 Data column4
Could anyone help if have an idea?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您刚刚向网格视图添加了另一列带有自定义标题的列。如果您想自定义第一列的标题,只需自定义第一个模板字段的标题即可:
如果此下拉列表太大或者您想在标题中添加一些附加文本,您始终可以为合并的其他 TemplateFields 创建 HeaderTemplate代码后面的一些列标题(例如“合并”两个第一个标题,gridView 的 ID 为
gridView1
):You just added another column with custom header to your gridview. If you want to customize a header of the first column, just customize the header of your first template field:
If this dropdownlist is too big or if you want add some additional text in the header, you can always create HeaderTemplate for other TemplateFields of merge some of the column's headers in code behind (example for "merging" two first headers, Id of the gridView is
gridView1
):好吧,您实际上并没有添加标题行,而是添加了标题列..这基本上只是具有更多控件的另一列..
为什么不将 DropDownList 放置在 GridView 之前,然后您可以在处理 DropDownList_SelectedIndexChanged 事件后面编写一些代码对数据进行排序?
well, you have not actually added a header row, but a header column .. which is basically just another column with more controls ..
why dont you place your DropDownList before your GridView, and then you can write some code behind handling the DropDownList_SelectedIndexChanged event to sort the Data ?
我在没有使用 GridView 中的过滤器的情况下实现了这一点。然后,您可以单独处理事件,并相应地填充 GridView。
您实际添加的是一列,而不是一行。这就是你得到这个结果的原因。
希望这有帮助!
I have implemented this without using the filters within the GridView. Then you can handle the events separately, and populate the GridView accordingly.
What you are actually adding is a column, instead of a row. That's why you are getting that result.
Hope this helps!