Wednesday, February 29, 2012

GridView vs DataList vs Repeater vs Formview vs DetailsView - which one to choose

Feature                  
Repeater  
 DataList  
 GridView
Table layout
No
No
Yes
Flow layout
Yes
Yes
No
Column layout
No
Yes
No
Style properties
No
Yes
Yes
Templates
Yes
Yes
Columns/optional
Select/ Edit/Delete
No
Yes
Yes
Sort
No
No
Yes
Paging
No
No
Yes

Tuesday, February 28, 2012

What is the difference between a property a method and an event? Give an example of each

1. Text1.color ------ is a property  
2. Text1.text   ------- is Method     
3. button 1. Click  -- is an event
What is the difference between a property a method and an event? Give an example of each.  
*Property are a type of method that shows state of an Object 
like Caption, backcolour  etc.
*Methods/Functions are for changing Or doing something on 
the Object Like Move,Remove, Add etc.
*Event are Objects which means that something happend for 
which the object must respond to. And for this very reason 
we write method like 
button1_Click( sender Object, event Object)
The event Object(Delegate) is related with the method of 
that responder Object(Button)

Monday, February 20, 2012

Fetch the data from Excel File at GridView

1.use this name space:-Imports System.Globalization
2.Add the Excel file in Solution Explorer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        fillgried()
    End Sub
    Function fillgrid()
        Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("Customers1.xlsx") + ";Extended Properties='Excel 12.0 Xml;HDR=YES;'"
        Dim query As String = "SELECT * FROM [customers$]"
        Dim excelDataSet As DataSet = New DataSet()
        excelDataSet.Locale = CultureInfo.InvariantCulture
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(query, strConn)
        da.Fill(excelDataSet)
        GridView1.DataSource = excelDataSet.Tables(0)
        GridView1.DataBind()
    End Function

Friday, February 17, 2012

Image Gallery using ASP.Net Grid View control

****Start Script*****
[head id="Head1" runat="server"]
    [title]GridView Images Example[/title]
[script type="text/javascript"]
    function LoadDiv(url) {
        var img = new Image();
        var bcgDiv = document.getElementById("divBackground");
        var imgDiv = document.getElementById("divImage");
        var imgFull = document.getElementById("imgFull");
        var imgLoader = document.getElementById("imgLoader");
        imgLoader.style.display = "block";
        img.onload = function () {
            imgFull.src = img.src;
            imgFull.style.display = "block";
            imgLoader.style.display = "none";
        };
        img.src = url;
        var width = document.body.clientWidth;
        if (document.body.clientHeight > document.body.scrollHeight) {
            bcgDiv.style.height = document.body.clientHeight + "px";
        }
        else {
            bcgDiv.style.height = document.body.scrollHeight + "px";
        }
       imgDiv.style.left = (width - 650) / 2 + "px";
        imgDiv.style.top = "20px";
        bcgDiv.style.width = "100%";
        bcgDiv.style.display = "block";
        imgDiv.style.display = "block";
        return false;
    }
    function HideDiv() {
        var bcgDiv = document.getElementById("divBackground");
        var imgDiv = document.getElementById("divImage");
        var imgFull = document.getElementById("imgFull");
        if (bcgDiv != null) {
            bcgDiv.style.display = "none";
            imgDiv.style.display = "none";
            imgFull.style.display = "none";
        }
    }
[/script]
****End Script***
***Css Start ***
[style type="text/css"]
     body 
     {
        margin:0;
        padding:0;
        height:100%; 
        overflow-y:auto;  
     }
     .modal
     {
        display: none; 
        position: absolute;
        top: 0px; 
        left: 0px;
        background-color:black;
        z-index:100;
        opacity: 0.8;
        filter: alpha(opacity=60);
        -moz-opacity:0.8;
        min-height: 100%;
     }
     #divImage
     {
        display: none;
        z-index: 1000;
        position: fixed;
        top: 0;
        left: 0;
        background-color:White;
        height: 550px;
        width: 600px;
        padding: 3px;
        border: solid 1px black;
     }
     * html #divImage {position:absolute;}
[/style]
***End Css***
***Start Body ***

[body]
    [form id="form1" runat="server"]
        [div]
            [br /]
[asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
  Font-Names="Arial"]
[Columns]
    [asp:TemplateField HeaderText="Preview Image"]
        [ItemTemplate]
            [asp:ImageButton ID="ImageButton1" runat="server"
            ImageUrl='<%# Eval("p_image")%>' Width="50px"
            Height="50px" Style="cursor: pointer"
            OnClientClick = "return LoadDiv(this.src);"/]
        [/ItemTemplate]
    [/asp:TemplateField]
[/Columns]
[/asp:GridView]
        [/div]
        [div id="divBackground" class="modal"]
[/div]
[div id="divImage" class = "info"]
    [table style="height: 100%; width: 100%"]
        [tr]
            [td valign="middle" align="center"]
                [img id="imgLoader" alt=""src="images/loader.gif" /]
                [img id="imgFull" runat="server" alt="" src=""style="display: none;
                height: 500px;width: 590px" /]
            [/td]
        [/tr]
        [tr]
            [td align="center" valign="bottom"]
                [input id="btnClose" type="button" value="close"onclick="HideDiv()"/]
            [/td]
        [/tr]
    [/table]
[/div]

 [/form]
[/body]
[/html]


Wednesday, February 15, 2012

display mouseover effect in GridView rows using only CSS?

ASPX Page:-


style type="text/css">
#GridView1 tr.rowHover:hover
{
background-color: Yellow;
font-family: Arial;
}
/style>;
asp:GridView ID="GridView1" runat="server" EnableViewState="false" RowStyle-CssClass="rowHover" ClientIDMode="Static" />




Tuesday, February 14, 2012

How do we read data from a XML file and display it in a DataGrid ?

using ReadXML method
DataSet MyDataset= new DataSet ();
MyDataset.ReadXml (Server.MapPath ("sample.xml"));
MyDataGrid.DataSource =MyDataset;
MyDataGrid.DataBind();

Tuesday, February 7, 2012

Select Year by DropDownList

protected void Page_Load(object sender, EventArgs e)
    {
        if (!(Page.IsPostBack))
        {
            for (int i = 1980; i < 2020; i++)
                DropDownList1.Items.Add(i.ToString());
            DropDownList1.Items.Insert(0, "Select Year");
        }
    }