Solved

Remove border within a specifi cell of gridview

Posted on 2014-10-28
11
1,027 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PErfect thanks
0
 

Author Comment

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

Regards
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 35

Expert Comment

by:Miguel Oz
Comment Utility
could you post your code to have a look?
0
 

Author Comment

by:arnololo123
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
"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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

772 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

12 Experts available now in Live!

Get 1:1 Help Now