Solved

Remove border within a specifi cell of gridview

Posted on 2014-10-28
11
1,206 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

776 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