Solved

Remove border within a specifi cell of gridview

Posted on 2014-10-28
11
1,132 Views
Last Modified: 2014-10-31
Hello ,

I have a gridview with  both gridline showing (vertical and horizontal).
But there is one colum for which I don't want to show the left border.
Any idea how I could do that?

REgards
0
Comment
Question by:arnololo123
  • 6
  • 4
11 Comments
 
LVL 7

Expert Comment

by:Katie Pierce
ID: 40409766
If you select Print Gridlines, Excel will print them for the entire range of data on your sheet.  A better option is to select that range and apply a border.  You can select specific cells, columns, etc. to have different formatting, removing the border if you like.

Highlight range > right click > Format Cells > Border > select style of border and which sides of cells to apply it to.
0
 

Author Comment

by:arnololo123
ID: 40409792
Thanks, but I am talking about a gridview in ASP.net not excel.
0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 40409933
On possible solution is to modify cell by cell basis:
1) Create a CSS class (hiderightborder) that set right border to 0.
.hideleftborder {
border-left-width: 0px;
}
</

Open in new window

2) Apply this class when needed to all cells in your target column as shown below:
private void HideColumn(Gridview grvEmployees, int colIndex)
    {
        grvEmployees.HeaderRow.Cells[colIndex].CssClass = "hideleftborder";

        foreach (GridViewRow row in grvEmployees.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
                row.Cells[colIndex].CssClass = "hideleftborder";
        }
    }

Open in new window

0
 

Author Closing Comment

by:arnololo123
ID: 40410352
PErfect thanks
0
 

Author Comment

by:arnololo123
ID: 40410359
sorry I spoke too fast, it does not work with Internet explorer 11.

Regards
0
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.

 
LVL 35

Expert Comment

by:Miguel Oz
ID: 40411995
could you post your code to have a look?
0
 

Author Comment

by:arnololo123
ID: 40412008
PLease find my code below. But it works great if I activate the compatibility view of with older version of IE but with IE11 it does not work

<asp:GridView ID="GV_hrsdetail" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="idhrsdetail" DataSourceID="SqlDS_hrsdetail" CellPadding="4" 
            ForeColor="#333333" 
            onrowdatabound="GV_hrsdetail_RowDataBound" 
            ondatabound="GV_hrsdetail_DataBound" EnableViewState="False">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <asp:BoundField DataField="item" HeaderText="Item" ReadOnly="true" />
                <asp:BoundField DataField="site" HeaderText="Location" SortExpression="site"  ReadOnly="true"/>
                <asp:BoundField DataField="function" HeaderText="Function" 
                    SortExpression="function"  ReadOnly="true"/>
                <asp:BoundField DataField="department" HeaderText="Department" 
                    SortExpression="department"  ReadOnly="true"/>
                <asp:BoundField DataField="joblevel" HeaderText="Job Level" 
                    SortExpression="joblevel"  ReadOnly="true"/>
                <asp:BoundField DataField="rate" HeaderText="Rate" SortExpression="rate"  ReadOnly="true"/>
                <asp:BoundField DataField="jan" HeaderText="jan" SortExpression="jan" />
                <asp:BoundField DataField="feb" HeaderText="feb" SortExpression="feb" />
                <asp:BoundField DataField="mar" HeaderText="mar" SortExpression="mar" />
                <asp:BoundField DataField="apr" HeaderText="apr" SortExpression="apr" />
                <asp:BoundField DataField="may" HeaderText="may" SortExpression="may" />
                <asp:BoundField DataField="jun" HeaderText="jun" SortExpression="jun" />
                <asp:BoundField DataField="jul" HeaderText="jul" SortExpression="jul" />
                <asp:BoundField DataField="aug" HeaderText="aug" SortExpression="aug" />
                <asp:BoundField DataField="sep" HeaderText="sep" SortExpression="sep" />
                <asp:BoundField DataField="oct" HeaderText="oct" SortExpression="oct" />
                <asp:BoundField DataField="nov" HeaderText="nov" SortExpression="nov" />
                <asp:BoundField DataField="dec" HeaderText="dec" SortExpression="dec" />
                <asp:BoundField DataField="costcenter" HeaderText="Cost Center" 
                    SortExpression="costcenter"  ReadOnly="true"/>
                <asp:BoundField DataField="ccmanager" HeaderText="CC Manager" 
                    SortExpression="ccmanager"  ReadOnly="true"/>
                <asp:BoundField DataField="tothrs" HeaderText="Tot. Hours" 
                    SortExpression="tothrs"  ReadOnly="true"/>
                <asp:BoundField HeaderText="Total Cost Local"  ReadOnly="true" 
                    ItemStyle-HorizontalAlign="Right" >
<ItemStyle HorizontalAlign="Right"></ItemStyle>
                </asp:BoundField>
                  <asp:BoundField  ItemStyle-HorizontalAlign="Left">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Currency Exchange"  ReadOnly="true"/>
                <asp:BoundField DataField="totcost" HeaderText="Total Cost Euro"   ItemStyle-HorizontalAlign="Right"
                    SortExpression="totcost"  ReadOnly="true" DataFormatString="{0:0.00}" >
<ItemStyle HorizontalAlign="Right"></ItemStyle>
                </asp:BoundField>
                    <asp:BoundField ItemStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left"></ItemStyle>
                </asp:BoundField>
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>

CODE BEHIND:
    protected void GV_hrsdetail_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[22].CssClass = e.Row.Cells[25].CssClass = "hideleftborder";
        }
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[21].ColumnSpan = 2;
            e.Row.Cells[22].Visible = false;
            e.Row.Cells[24].ColumnSpan = 2;
            e.Row.Cells[25].Visible = false;
        }
    }
In my CSS file:
    .hideleftborder {
border-left-width: 0px;
}

Open in new window

0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 40412637
I do not think you can use ColumnSpan and visible false construct.  If what you need is to span column [21] and [24] and "hide" the adjacent cell then you need to use RemoveAt method as shown here
0
 

Author Comment

by:arnololo123
ID: 40412894
Hello I did try to  use the Removeat method but the result is the same, the border is still showing.
Please see picture.

    protected void GV_hrsdetail_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[24].ColumnSpan = 2;
            e.Row.Cells.RemoveAt(25);

            e.Row.Cells[21].ColumnSpan = 2;
            e.Row.Cells.RemoveAt(22);
        }
    }

Open in new window


Thanks
test.png
0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 40414914
"border is still showing"
Does it mean that you do need the border between the number and USD?
If it is then please put back my original code (first) applied to the cells only and leave the current Header code as it is working OK.
0
 

Author Comment

by:arnololo123
ID: 40416152
Hello,

No I don't want the border between the number and USD, I want to keep it as two cells but I need the border between the two to be removed.   The border is showing if I don't have the compatibility view activated.
The header is fine the way it is.

Thanks
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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

910 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

19 Experts available now in Live!

Get 1:1 Help Now