Solved

Asp.net Gridview question

Posted on 2014-01-27
4
22 Views
Last Modified: 2016-06-13
I have the following Asp.net C# code for the Asp.net web application that shows a Gridview table like the one attached below.

Could you please help me update the code below to remove the Templatefields (with HeaderText="H7" and HeaderText="H8") as highlighted in the attached picture. I need the entire highlighted part removed. I need to somehow hide these 2 columns instead of deleting as the fields are referenced in the code elsewhere. Also with the above hide, I need to hide the part of the table above holding a blank space cell. thank you.

<asp:Panel ID="pnlChart" runat="server" Style="width:100%; padding-left:5px">
         <asp:Label ID="lblChartTitle" runat="server" Text="" Visible="false" CssClass="MetricTitle"></asp:Label>
         <div id="divFullView"  style="width:100%; text-align:right; display:none"><asp:HyperLink   ID="hlnkFullView" runat="server" Target="_blank" Style="color: #F40C42">Full Screen View</asp:HyperLink></div>
          <asp:UpdatePanel ID="upnlPHD" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <div id="divPHD" runat="server" visible="false" style=" line-height:0px">
         <br />
         <br />
           
         <table id="tblRadio" width="1075px" cellspacing="0px" style="line-height:normal">
            <tbody>
                <tr>
                <th align="left"  colspan="4" style="border-right:solid 1px;">
                   <span id="lblLoadingDrilldown" style="display:none; color:Red" >Loading dashboard...Please wait</span>                      
                </th>
               <%-- <th align="center" scope="col">
                   
                </th>
                <th align="center" scope="col">
                   
                </th>--%>
                <th colspan="2" align="center" scope="col"  id="th1" style="   border-top:solid 1px; "  >
                    <asp:RadioButton ID="rb1" runat="server" onclick="toggleDrillDownLink(this);" Checked="true" />
                </th >
                <th id="th2" align="center" scope="col" style="border-left:solid 1px;   border-top:solid 1px" >
                    <asp:RadioButton ID="rb2" runat="server" onclick="toggleDrillDownLink(this);"   />
                </th>
                 <th id="th3" align="center" scope="col" style=" border-left:solid 1px; border-right:solid 1px; border-top:solid 1px" >
                    <asp:RadioButton ID="rb3" runat="server" onclick="toggleDrillDownLink(this);"   />
                </th>
                 <th id="th4" align="center" scope="col" style=" border-left:solid 1px; border-right:solid 1px; border-top:solid 1px" >
                    <asp:RadioButton ID="rb4" runat="server" onclick="toggleDrillDownLink(this);"   />
                </th>
               
                <th  scope="col" align="right" >                     
                     <asp:UpdatePanel ID="upnlOpenDrilldown" runat="server">
                        <ContentTemplate>
                            <asp:Button     ID="btnDrillDown" runat="server" Text="Drilldown" CssClass="formButton"  OnClientClick="return openPhdDrilldown();"
                                 />
                        </ContentTemplate>
                       
                    </asp:UpdatePanel>    
                </th>
            </tr>
                <tr>
                    <td style="width:75px"></td>
                    <td style="width:100px"></td>
                    <td style="width:100px"></td>
                    <td style="width:100px"></td>
                    <td style="width:100px;margin:0px; padding:0px"></td>
                    <td style="width:100px;margin:0px; padding:0px"></td>
                    <td style="width:100px;margin:0px; padding:0px"></td>
                    <td style="width:100px;margin:0px; padding:0px"></td>
                    <td style="width:100px;margin:0px; padding:0px"></td>
                     <td style="width:100px;margin:0px; padding:0px"></td>
                     <td style="width:100px;margin:0px; padding:0px"></td>
                   
             
                 </tr>
            </tbody>
         </table>
         <asp:GridView ID="gvDashboard1" runat="server"
                 AutoGenerateColumns="false"
                 HeaderStyle-Wrap="true"
                 HeaderStyle-CssClass="headerRow"
                 Width="1075px"
                 style="line-height:normal"
                 RowStyle-Height="20px"
                 DataKeyNames="ID,FKDSW_ID"
                 AllowSorting="true"
                 onrowdatabound="gvDashboard1_RowDataBound"
                 onsorting="gvDashboard1_Sorting">
            <Columns>
                <asp:TemplateField HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="75px" ItemStyle-VerticalAlign="Middle" >
                    <HeaderTemplate>
                        <div style="padding:5px;">
                            <asp:CheckBox ID="chkSelectAll" runat="server" onclick="selectAll(this);"/>
                        </div>
                    </HeaderTemplate>
                    <ItemTemplate >
                        <div style="padding:5px;">
                            <asp:CheckBox ID="chkSelectVersion" runat="server" onclick="selectVersion(this)"  />
                            <asp:HiddenField   ID="hdnSwVersion" runat="server" Value='<%# Eval("V1") %>' />
                        </div>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField  HeaderText="H1a" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" SortExpression="H1a" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl1" runat="server"   Text='<%# Eval("V3") %>' ToolTip='<%# Eval("V2","{0}") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField  HeaderText="H1" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" SortExpression="H1" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl2" runat="server"   Text='<%# Eval("V4") %>' ToolTip='<%# Eval("V5").ToString().Replace(",", " ") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="H3" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" SortExpression="H3" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl3" runat="server"   Text='<%# Eval("V6", "{0:#,##0}") %>'></asp:Label>
                    </ItemTemplate>
                   
                </asp:TemplateField>
                <asp:TemplateField HeaderText="H4" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" SortExpression="H4" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl4" runat="server"   Text='<%# Eval("V7" , "{0:#,##0}") %>' ></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="H5" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" SortExpression="H5" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl5" runat="server"   Text='<%# Eval("V8" , "{0:#,##0}") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="H6" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" SortExpression="H6" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl6" runat="server"   Text='<%# Eval("V9","{0}") %>'></asp:Label>
                        <asp:Label ID="lbl7" runat="server"   Text='N/A' Visible="false"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="H7" ItemStyle-Width="0px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" SortExpression="H7" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl8" runat="server"   Text='<%# Eval("V10","{0:0.00000}") %>'></asp:Label>
                        <asp:Label ID="lbl9" runat="server"   Text='N/A' Visible="false"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="H8" ItemStyle-Width="0px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" SortExpression="H8" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl10" runat="server"   Text='<%# Eval("V11","{0:0.00000}") %>'></asp:Label>                                          
                        <asp:Label ID="lbl11" runat="server"   Text='N/A' Visible="false"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                 <asp:TemplateField HeaderText="H9" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"  SortExpression="H9" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl12" runat="server"   Text='<%# Eval("V12","{0:#,##0}") %>'></asp:Label>
                       <asp:Label ID="lbl13" runat="server"   Text='N/A' Visible="false"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
               
                <asp:TemplateField HeaderText="H10" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" SortExpression="H10" HeaderStyle-ForeColor="#757E82">      
                    <ItemTemplate>
                        <asp:Label ID="lbl14" runat="server"   Text='<%# BindConfidence(Eval("V13")) %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        </div>
            </ContentTemplate>
           
         </asp:UpdatePanel>
    </asp:Panel>

gridview
0
Comment
Question by:toooki
4 Comments
 
LVL 4

Expert Comment

by:ItWorked
ID: 39811377
You can set
Visible="false"

Open in new window

on those two TemplateField controls so that those won't be visible at the client side.(Assuming you aren't using any client side JS which depends on cell operation).

For Removing white space : Is the first item in your datasource coming empty? if yes then you need to handle that in your data source(well that depends on what DataSource you are using)

In case if it's coming because of HMTL markup then you need to share HTML markup with the viewers.
0
 
LVL 7

Accepted Solution

by:
Kishan Zunjare earned 500 total points
ID: 39811460
You can set through code behind...

protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
         e.Row.Cells[columnIndex].Visible = false;
}
0
 

Author Comment

by:toooki
ID: 39858394
Thank you for your help. I am checking the solution.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question