C#.net DataGridView 合并表头单元格 80
4个回答
展开全部
<asp:GridView style="TEXT-ALIGN: center" id="gvManualSign" runat="server" Width="100%" AllowPaging="True" PageSize="8" AutoGenerateColumns="False" BorderColor="#42A5A3" OnRowDataBound="gvManualSign_RowDataBound" OnPageIndexChanging="gvManualSign_PageIndexChanging">
<FooterStyle CssClass="footerCss"></FooterStyle>
<Columns>
<asp:TemplateField Visible="False"><ItemTemplate>
<asp:Label id="lblUserId" runat="server" Text='<%# Eval("UserId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="User" HeaderText="姓名"><EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("UserName") %>' id="TextBox1"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("UserName") %>' id="Label1"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="出勤率(%)"><ItemTemplate>
<asp:Label id="lblEfficiency" runat="server" Text='<%# GetEfficiency(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="迟到次数"><ItemTemplate>
<asp:Label id="lblLate" runat="server" Text='<%# GetLate(Eval("UserId")) %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="早退次数"><ItemTemplate>
<asp:Label id="lblLeave" runat="server" Text='<%# GetLeave(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="矿工次数"><ItemTemplate>
<asp:Label id="lblMiner" runat="server" Text='<%# GetMiner(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="所属部门"><ItemTemplate>
<asp:Label id="lblDepart" runat="server" Text='<%# GetDepart(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="所属机构"><ItemTemplate>
<asp:Label id="lblBranch" runat="server" Text='<%# GetBranch(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="White" Height="20px" CssClass="rowCss"></RowStyle>
<HeaderStyle BackColor="#42A5A3" Height="20px" CssClass="headerCss" Wrap="True"></HeaderStyle>
</asp:GridView>
#region gridveiw的格式显示 Unite(gvManualSign)
/// <summary>
/// gridveiw的格式显示
/// </summary>
/// <param name="gv"></param>
protected void Unite(GridView gvManualSign)
{
//全局行
int i;
//接收单元格的值
string gvText;
//定义下一格单元格的索引
int nextCell;
if (gvManualSign.Rows.Count > 0)
{
for (int j = 0; j < 8; j++)
{
//只有签卡姓名、部门、机构需合并单元格
if (j != 0 && j != 1 && j != 2 && j != 3 && j != 4 && j != 5)
{
//接收第一行中单元格的值
gvText = gvManualSign.Rows[0].Cells[j].Text;
//第一行单元格的合并为1
gvManualSign.Rows[0].Cells[j].RowSpan = 1;
nextCell = 0;
//循环遍历GridView中每行的值
for (i = 1; i < gvManualSign.Rows.Count; i++)
{
//当遍历的值等于第一行中的值时,合并单元格++
if (gvManualSign.Rows[i].Cells[j].Text == gvText)
{
gvManualSign.Rows[i].Cells[j].Visible = false;
gvManualSign.Rows[nextCell].Cells[j].RowSpan++;
}
else
{
//否则就把这格单元格的值付给全局值
gvText = gvManualSign.Rows[i].Cells[j].Text;
//为全局行赋值
nextCell = i;
//本行中的合并单元格就为一
gvManualSign.Rows[i].Cells[j].RowSpan = 1;
}
}
}
}
}
}
#endregion
可以参考参考!!!!
<FooterStyle CssClass="footerCss"></FooterStyle>
<Columns>
<asp:TemplateField Visible="False"><ItemTemplate>
<asp:Label id="lblUserId" runat="server" Text='<%# Eval("UserId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="User" HeaderText="姓名"><EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("UserName") %>' id="TextBox1"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("UserName") %>' id="Label1"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="出勤率(%)"><ItemTemplate>
<asp:Label id="lblEfficiency" runat="server" Text='<%# GetEfficiency(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="迟到次数"><ItemTemplate>
<asp:Label id="lblLate" runat="server" Text='<%# GetLate(Eval("UserId")) %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="早退次数"><ItemTemplate>
<asp:Label id="lblLeave" runat="server" Text='<%# GetLeave(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="矿工次数"><ItemTemplate>
<asp:Label id="lblMiner" runat="server" Text='<%# GetMiner(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="所属部门"><ItemTemplate>
<asp:Label id="lblDepart" runat="server" Text='<%# GetDepart(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="所属机构"><ItemTemplate>
<asp:Label id="lblBranch" runat="server" Text='<%# GetBranch(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="White" Height="20px" CssClass="rowCss"></RowStyle>
<HeaderStyle BackColor="#42A5A3" Height="20px" CssClass="headerCss" Wrap="True"></HeaderStyle>
</asp:GridView>
#region gridveiw的格式显示 Unite(gvManualSign)
/// <summary>
/// gridveiw的格式显示
/// </summary>
/// <param name="gv"></param>
protected void Unite(GridView gvManualSign)
{
//全局行
int i;
//接收单元格的值
string gvText;
//定义下一格单元格的索引
int nextCell;
if (gvManualSign.Rows.Count > 0)
{
for (int j = 0; j < 8; j++)
{
//只有签卡姓名、部门、机构需合并单元格
if (j != 0 && j != 1 && j != 2 && j != 3 && j != 4 && j != 5)
{
//接收第一行中单元格的值
gvText = gvManualSign.Rows[0].Cells[j].Text;
//第一行单元格的合并为1
gvManualSign.Rows[0].Cells[j].RowSpan = 1;
nextCell = 0;
//循环遍历GridView中每行的值
for (i = 1; i < gvManualSign.Rows.Count; i++)
{
//当遍历的值等于第一行中的值时,合并单元格++
if (gvManualSign.Rows[i].Cells[j].Text == gvText)
{
gvManualSign.Rows[i].Cells[j].Visible = false;
gvManualSign.Rows[nextCell].Cells[j].RowSpan++;
}
else
{
//否则就把这格单元格的值付给全局值
gvText = gvManualSign.Rows[i].Cells[j].Text;
//为全局行赋值
nextCell = i;
//本行中的合并单元格就为一
gvManualSign.Rows[i].Cells[j].RowSpan = 1;
}
}
}
}
}
}
#endregion
可以参考参考!!!!
展开全部
在EditDataGridView控件中,用HTML中的table来规范表格,即可弄成你要的格式
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是WinForm吧,怎么可以用html?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这问题没见过,像一楼说的用HTML控件来做,做怎么样的都行。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询