Total Pageviews

2 May 2012

How show value in grid view in ASP.net

About.aspx=>
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="About.aspx.cs" Inherits="About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:GridView ID="GridView1" runat="server"
        >
    </asp:GridView>
</asp:Content>
About.aspx.cs=>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
public partial class About : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    string s = ConfigurationManager.ConnectionStrings["conn"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(s);
       if (!IsPostBack)
        {
            BindGridView();
        }
    }
    public void BindGridView()
    {
        SqlDataAdapter ad = new SqlDataAdapter("select * from Employees order by EmployeeID", con);
        DataSet ds = new DataSet(); ad.Fill(ds);
        GridView1.DataSource = ds; GridView1.DataBind();
    }

   
}

How delete check box wise in Grid view data ASP.net

Default.aspx=>
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
     

</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
         <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
             AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID"
             Width="41px" CellPadding="4" ForeColor="#333333" GridLines="None"
             onselectedindexchanged="GridView1_SelectedIndexChanged" Height="32px">   
        
               <Columns>         
                       <asp:CommandField ShowSelectButton="True" />
                                         <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" InsertVisible="False" ReadOnly="True" /> 
                                                         <asp:BoundField DataField="Firstname" HeaderText="Firstname"  />                 
                                                         <asp:TemplateField HeaderText="Select">
                                                                               <ItemTemplate>   
                                                                                                     
                                                                                                     
                                         <asp:CheckBox ID="chkSelect" runat="server" />    </ItemTemplate>  <HeaderTemplate>
                                        <%--<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server" type="checkbox" />--%>     
                                         
                                                     </HeaderTemplate>         
                                                             </asp:TemplateField>       
                                                                  </Columns>   
                                                                       </asp:GridView>       
<br />
<br />        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Delete" /> 
       <asp:Label ID="lblmsg" runat="server" Text="Label" Visible="false"></asp:Label>
</asp:Content>
Default.aspx.cs=>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()); 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridView();
        }
    }
    public void BindGridView()
    {
        SqlDataAdapter ad = new SqlDataAdapter("select * from tbl_CustomerDetail order by CustomerID", con);
        DataSet ds = new DataSet(); ad.Fill(ds);
        GridView1.DataSource = ds; GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox cb = ((CheckBox)(row.FindControl("chkSelect")));
            if (cb != null && cb.Checked)
            {
                int custID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
                string sqlstr = "delete from tbl_CustomerDetail where CustomerID='" + custID + "'"; SqlCommand mycmd;
                mycmd = new SqlCommand(sqlstr, con);
                con.Open();
                mycmd.ExecuteNonQuery();
                BindGridView();
            }
            con.Close();
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()); 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridView();
        }
    }
    public void BindGridView()
    {
        SqlDataAdapter ad = new SqlDataAdapter("select * from tbl_CustomerDetail order by CustomerID", con);
        DataSet ds = new DataSet(); ad.Fill(ds);
        GridView1.DataSource = ds; GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox cb = ((CheckBox)(row.FindControl("chkSelect")));
            if (cb != null && cb.Checked)
            {
                int custID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
                string sqlstr = "delete from tbl_CustomerDetail where CustomerID='" + custID + "'"; SqlCommand mycmd;
                mycmd = new SqlCommand(sqlstr, con);
                con.Open();
                mycmd.ExecuteNonQuery();
                BindGridView();
            }
            con.Close();
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
}

ASP.net Web Template with extension


Web TemplateExtension
Web Form.aspx
Master Page.master
Web User Control.ascx
ADO.net Entity Data Model.edmx
ADO.net Entityobject Generator.tt
ADO.NET Self-Tracking Generator.tt
Ajax-enabled WCF service.svc
Browser File.browser
Class.cs
Class Diagram.cd
Crystal Report.rpt
Dataset.xsd
Dyanamic Data Field.ascx
Generic Handler.ashx
HTML Page.htm 0r.html
JScript File.js
process Text Template.tt
LINQ to SQL Classes].dbml
Report.rdlc
Report Wizard.rdlc
Resources File.resx
Silverlight1.0 JScript  .Xaml
Silverlight Application.Xaml
Silverlight -enable WCF Services.svc
Site Map.sitemap
Skin File.skin
SQL Server Database.mdf
Stylesheet.css
Text File.txt
Text Template.tt
WCF Data Services.svc
WCF Service.svc
Web Configuration File.config
Web  Service.aspmx
XML File.xml
XML Schema.xsd
XSLT File.xslt
Sequence Diagram.sequencediagram

ASP .Net Life cycle

Page Life Cycle of an ASP.NET The life cycle starts when a user requests a web page through his/her browser. The Web server than process the page through a sequence of steps before response is sent back to the user's browser. The steps are as:
1. Page Request
2. Start
3. Page Initialization
4. Load
5. Validation
6. PostBack Event Handling
7. Render
8. Unload

Page Request
The page request occurs before the page life cycle begins. When a user requests the page, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.
Start
In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.
Page Initialization
During page initialization, controls on the page are available and each control's UniqueID are generated but not their properties. Any themes are also applied to the page.
Developers have access to the Init, InitComplete and PreLoad methods in this stage. The methods are as follows:
* Init: This event is raised after all controls have been initialized and any skin settings have been applied. This event is used to read or initialize control properties.
* InitComplete: The Page object raises this event. This event is used for processing tasks that require completion of all initialization.
* PreLoad: Use this event if you need to perform processing on your page or control before the Load event. After the Page raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Request instance.
Load
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state. The OnLoad event method is fired during this stage.
This is where you will want to set properties for all of the server controls on your page, request query strings, and establish database connections.
Validation
During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.
PostBack Event Handling
If the request is a postback, any event handlers are called. The event handling for server controls occurs during this stage.
Render
During rendering, view state is saved to the page and then the page calls on each control to contribute its rendered output to the OutputStream of the page's Response property. Render is not really an event. The HTML of the page and all controls are sent to the browser for rendering.
Unload
Unload is called when the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed. The cleanup includes routines such as closing database connections and file streams, or, event logging and other tasks.
Conclusion
When a Web page is requested, the server creates objects associated with the page and all of its child controls objects and uses these to render the page to the browser. Once the final stage is complete, the w

Contact Form

Name

Email *

Message *