Solved

Remove border within a specifi cell of gridview

Posted on 2014-10-28
11
1,359 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 36

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
LVL 36

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 36

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 36

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

685 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