Solved

How to edit the style of the "Edit" column in a .NET gridview

Posted on 2015-02-06
2
70 Views
Last Modified: 2015-04-28
Hi all,

I have created a GridView on a .NET 2.0 (I know, I know...) web page that has an Edit command.  The Edit command, obviously, opens up the column with the "Update" and "Cancel" link buttons.  

The style that our office's web site uses makes the two link buttons appear really close together.  Does anyone know what sort of command/style I can use to either space them apart more or put a "|" between the two link buttons or what have you?  

Thanks,
Jamie
0
Comment
Question by:Jamie Fellrath
2 Comments
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 500 total points
ID: 40595370
Try this
http://forums.asp.net/t/1682829.aspx?Is+it+possible+to+change+css+of+a+specific+column+of+GridView+control+at+run+time+

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
    protected void btnShow_Click(object sender, EventArgs e)
    {
        grvEmployees.HeaderRow.Cells[0].CssClass = "viscol";
        foreach (GridViewRow row in grvEmployees.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
                row.Cells[0].CssClass = "viscol";
        }
    }

    protected void btnHide_Click(object sender, EventArgs e)
    {
        grvEmployees.HeaderRow.Cells[0].CssClass = "hiddencol";

        foreach (GridViewRow row in grvEmployees.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
                row.Cells[0].CssClass = "hiddencol";
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Pager template example</title>
    <style type="text/css">
        .hiddencol
        {
            display: none;
        }
        .viscol
        {
            display: block;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="grvEmployees" runat="Server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
            AllowPaging="True">
            <Columns>
                <asp:BoundField HeaderText="ProductID" DataField="ProductID" />
                <asp:BoundField HeaderText="ProductName" DataField="ProductName" />
                <asp:BoundField HeaderText="UnitPrice" DataField="UnitPrice" />
            </Columns>
        </asp:GridView>
        <br />
        <asp:Button ID="btnShow" runat="server" Text="Show first column" OnClick="btnShow_Click" />&nbsp;
        <asp:Button ID="btnHide" runat="server" Text="Hide first column" OnClick="btnHide_Click" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT [ProductID] ,[ProductName],[UnitPrice] FROM [dbo].[Products]"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" />
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 1

Author Closing Comment

by:Jamie Fellrath
ID: 40748662
Thank you!
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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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