Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Remove border within a specifi cell of gridview

Posted on 2014-10-28
11
Medium Priority
?
1,680 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Technology Partners: 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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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 …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

721 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