在GridView中合并数据 [英] Merge Data in gridview
本文介绍了在GridView中合并数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有gridview之类的
Hello,
I have gridview like
<asp:GridView ID="gvShowRequests" runat="server" AllowPaging="true"
AutoGenerateColumns="false" Width="60%"
CssClass="gvRows" AllowSorting="false" GridLines="Both"
BorderColor="Black" PagerStyle-CssClass="pager"
OnPageIndexChanging="gvShowRequests_PageIndexChanging"
onselectedindexchanged="gvShowRequests_SelectedIndexChanged">
<RowStyle CssClass="gvRows" />
<AlternatingRowStyle CssClass="gvRowsalt" />
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" Visible="false" />
<asp:BoundField DataField="Name" HeaderText="Application" />
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:BoundField DataField="Type" HeaderText="Request Type" />
<asp:BoundField DataField="Status" HeaderText="Request Status" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="EmployeeID" HeaderText="Employee ID" />
<asp:BoundField DataField="AddedOn" HeaderText="Added On" />
</Columns>
</asp:GridView>
我想要的是:在标题Name
下的一列中显示First Name
,Last Name
和EmployeeID
What I want is : Display First Name
, Last Name
and EmployeeID
in one column under header Name
How can I do it?
推荐答案
将查询更改为
change query as
select id,(fname + '' +lname) as Name from tablename
现在绑定为
and now bind as
<asp:boundfield datafield="Name" headertext="Application" sortexpression="Name" xmlns:asp="#unknown" />
请尝试以下代码合并网格视图的单元格
我认为这可能对您有帮助
Please try this code to merge cell of your grid view
i thing it may help you
public static void MergeRows(GridView gridView)
{
for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = gridView.Rows[rowIndex];
GridViewRow previousRow = gridView.Rows[rowIndex + 1];
for (int i = 0; i < row.Cells.Count; i++)
{
if (row.Cells[i].Text == previousRow.Cells[i].Text)
{
row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 :
previousRow.Cells[i].RowSpan + 1;
previousRow.Cells[i].Visible = false;
}
}
}
}
我认为此链接将解决您的问题.
http://weblogs.asp.net/brijmohan/archive/2011/09/03/rows-and-columns-merging-in-asp-net-gridview-control.aspx [
I think this link will solve your problem.
http://weblogs.asp.net/brijmohan/archive/2011/09/03/rows-and-columns-merging-in-asp-net-gridview-control.aspx[^]
这篇关于在GridView中合并数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文