connectseekers.com

Thursday, 1 June 2017

How to Display Mouseover Effect in WebGrid Rows Using Only CSS

6/01/2017 - By Pranav Singh 0

This article will show you how to display mouseover effect in webgrid rows using only css. In this there is no use of jquery or JavaScript code to show the highlight effect.

Some of my previous articles are as follows: Asp.Net MVC : WebGrid Image Binding With Shorting Data Using C#.Net, Asp.Net MVC : WebGrid Image Binding Using C#.Net.

So for  this article first we will create   a new mvc application and add the below model class code.

public class CountryModel
    {
        public List<Country> CountryList { get; set; }
    }
    public class Country
    {
        public string CountryName { get; set; }
        public int Population { get; set; }
        public string FlagURL { get; set; }
    }

Now check the code of controller.

  //
        // GET: /Home/
        [HttpGet]
        public ActionResult Index()
        {
            CountryModel _countryModel = new CountryModel();
            _countryModel.CountryList= GetCountryList();
            return View(_countryModel);
        }

        ///

        /// Country list
        ///
        public List<Country> GetCountryList()
        {
            List<Country> _country = new List<Country>();
            _country.Add(new Country { CountryName = "India", Population = 124000, FlagURL = "CountryFlag/india.png" });
            _country.Add(new Country { CountryName = "China", Population = 84545, FlagURL = "CountryFlag/china.png" });
            _country.Add(new Country { CountryName = "Germany", Population = 9354999, FlagURL = "CountryFlag/germany.png" });
            _country.Add(new Country { CountryName = "Japan", Population = 24999, FlagURL = "CountryFlag/japan.png" });
            return _country;

        }

        
In above code I have prepared the code to pass the data to model from controller to view. Now we will create the view and add the below code to bind and styling the grid view.

@model MVC_Demos.Models.CountryModel
@{
    ViewBag.Title = "How to Display Mouseover Effect in WebGrid Rows Using Only CSS";
}

<style type="text/css">
    .gridtable {
        font-family: verdana,arial,sans-serif;
        font-size: 11px;
        color: #333333;
        border-width: 1px;
        border-color: #666666;
        border-collapse: collapse;
    }

        .gridtable th {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #666666;
            background-color: #dedede;
        }

        .gridtable td {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #666666;
            background-color: #ffffff;
        }

    .gridtable  tr:hover td,
    .gridtable  tr.even:hover td.active,
    .gridtable  tr.odd:hover td.active {
        background: #b6ff00;
    }
</style>

@using (Html.BeginForm("Index", "Home"))
{
    <table width="100%" cellpadding="5" cellspacing="2" border="0" style="background-color: White;">
        <tr>
            <td>
                @{
    var grid = new WebGrid(source: Model.CountryList,
    rowsPerPage: 10,
    canSort: true);

                }
                @grid.GetHtml(
                    tableStyle: "gridtable",
                    alternatingRowStyle: "even",
                    columns: grid.Columns(
                    grid.Column("CountryName", "CountryName"),
                    grid.Column("Population", "Population"),
                    grid.Column("FlagURL", header: "Country Flag", format: @<img src="~/@item.FlagURL" alt="@item.CountryName" width="30px;" />)
))
            </td>
        </tr>
    </table>
}

In above code please check the highlighted part of the code of css style. This code us responsible for highlighting the row on mouse over.  Now we have done run the application to check the output.




About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top