Solved

Asp.net Gridview question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Combine two datatables into one based on a value from second datatable 4 32
DateTimepicker 4 33
Error on Add method 1 36
Visual Studio TFS - how do I check in my code? 2 28
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!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

943 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

1 Experts available now in Live!

Get 1:1 Help Now