Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, 29 October 2013

Enable view state made false...see the difference


<--------------------------Enable View State is Made on------------------------------------------------>
<--------------------------------------------------------------------------------------------------------->
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;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {

            Getdata();
       
        }
    }

        private void Getdata()
        {
       
           string strcon= ConfigurationManager.ConnectionStrings["ConnectionStringdb"].ConnectionString;

            using(SqlConnection con= new SqlConnection(strcon))
            {
                con.Open();
                SqlCommand cmd= new SqlCommand("emp",con);
                cmd.CommandType= CommandType.StoredProcedure;
                GridView1.DataSource=cmd.ExecuteReader();
                GridView1.DataBind();
                con.Close();
           
            }
       
       
        }
    }
//if you hit the button the next time....the gridview displays the data....





<-------------------------------Enable View State is Made off-------------------------------------------->
<--------------------------------------------------------------------------------------------------------->


If you hit button ...then no grid
If you hit f5...its pageload...so grid displays





--Webconfig
<connectionStrings>
<add name="ConnectionStringdb" connectionString="Data Source=X.X.X.X;          Initial Catalog=anurag;          Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>


sql


create table employees
(
name varchar(40),
age int,
sex varchar(30)
)

insert into employees
select 'anurag',24,'m'
union all select 'anurag',24,'m'
union all select 'abhishek',22,'m'
union all select 'ruchi',23,'f'

select * from employees

alter procedure emp
as
begin
select * from employees
end



No comments:

Post a Comment