Solved

Asp.net Gridview question

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now