DataGrid View is used to display the information in alternate rows and if the rows are empty, then no columns are visible. You can also use different colors for the alternate rows but it's another task.
Here, we are dynamically merging the column in GridView.
The above picture shows that if the row is empty, then we need to merge all the columns. Also, not to show the cell border.
- <asp:UpdatePanel runat="server" ID="updatedata">
- <ContentTemplate>
- <div class="row text-center">
- <asp:Label ID="lblMsg" runat="server" EnableViewState="false"></asp:Label>
- </div>
- <asp:GridView ID="grd_data" runat="server" ViewStateMode="Disabled" AutoGenerateColumns="false" Width="100%" Height="100%" AlternatingRowStyle-BackColor="#CDFFFF" HeaderStyle-Font-Italic="true" OnRowDataBound="GridDatabound" RowStyle-CssClass="RowStyle" HeaderStyle-HorizontalAlign="Center" GridLines="Both" CssClass="griedline col-12" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="45" overflow="auto">
- <HeaderStyle HorizontalAlign="Center" CssClass="grdheader" />
- <Columns>
- <asp:BoundField HeaderText="LINE" DataField="line" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
- <asp:BoundField HeaderText="MAINT" DataField="maint" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
- <asp:BoundField HeaderText="W D." DataField="wd" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
- <asp:BoundField HeaderText="STORE" DataField="stores" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
- <asp:BoundField HeaderText="QUALITY" DataField="quality" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
- <%-- <asp:TemplateField>
- <HeaderTemplate><p> <h1> <i>Line</i></h1 ></p></HeaderTemplate>
- <ItemTemplate>
- <h1> <i><center> <asp:Label ID="lbl_line" runat="server" Text='<%#Eval("line") %>'></asp:Label>
- </center>
- </i>
- </h1>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <HeaderTemplate>
- <h1><i> Maint.</i></h1>
- </HeaderTemplate>
- <ItemTemplate>
- <h1>
- <center>
- <asp:Label ID="lbl_maint" runat="server" Text='<%# Eval("maint") %>'></asp:Label>
- </center>
- </h1>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <HeaderTemplate>
- <h1><i>WD.</i></h1>
- </HeaderTemplate>
- <ItemTemplate>
- <h1>
- <center>
- <asp:Label ID="lbl_wd" runat="server" Text='<%# Eval("wd") %>'></asp:Label>
- </center>
- </h1>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <HeaderTemplate>
- <h1><i> Stores</i></h1>
- </HeaderTemplate>
- <ItemTemplate>
- <h1>
- <center>
- <asp:Label ID="lbl_stores" runat="server" Text='<%# Eval("stores") %>'></asp:Label>
- </center>
- </h1>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField>
- <HeaderTemplate>
- <h1><i>Quality</i></h1>
- </HeaderTemplate>
- <ItemTemplate>
- <h1>
- <center>
- <asp:Label ID="lbl_quality" runat="server" Text='<%# Eval("quality") %>'></asp:Label>
- </center>
- </h1>
- </ItemTemplate>
- </asp:TemplateField>--%> </Columns>
- </asp:GridView>
- <%--<asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="updatetimer_Tick" >--%> </asp:Timer>
- </ContentTemplate>
- </asp:UpdatePanel>
- private void mergecolumn() {
- for (int i = 0; i < grd_data.Rows.Count; i++) {
- if (i % 2 == 0) {
- for (int j = 0; j < grd_data.Rows[i].Cells.Count; j++) {
- grd_data.Rows[i].Cells[j].Visible = false;
- grd_data.Rows[i].Attributes.Add("colspan", "5");
- }
- }
- }
- }