Solved

Asp.net Gridview question

Posted on 2014-01-27
4
25 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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