Solved

Asp.net Gridview question

Posted on 2014-01-27
4
26 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

687 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