Monday, June 30, 2014

multi Stored Procedure Binding DropDown list Selected Values To bing Gridview Using Sessions

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class drpgrid : System.Web.UI.Page
{
    adosession obj;
    protected void Page_Load(object sender, EventArgs e)
    {

        obj = new adosession();



        DataSet ds = obj.bindgrid(Convert.ToInt32(Session["id"]), "ById");


        DataTable dt = new DataTable();
        dt.Columns.Add("id", typeof(int));
        dt.Columns.Add("name", typeof(string));
        dt.Columns.Add("address", typeof(string));

        if (Session["dt"] == null)
        {
            dt.Rows.Add(ds.Tables[0].Rows[0][0].ToString(), ds.Tables[0].Rows[0][1].ToString(), ds.Tables[0].Rows[0][2].ToString());
            grd.DataSource = dt;
            grd.DataBind();
            Session["dt"] = dt;
        }
        else
        {
            DataTable dt2 = (DataTable)Session["dt"];
            dt2.Rows.Add(ds.Tables[0].Rows[0][0].ToString(), ds.Tables[0].Rows[0][1].ToString(), ds.Tables[0].Rows[0][2].ToString());
            Session["dt"] = dt2;
            grd.DataSource = dt2;
            grd.DataBind();
        }

    }
}

 -----------------------------------------------------------------------------------
Stored Procedure
USE [naresh]
GO

/****** Object:  StoredProcedure [dbo].[sp_getgridvalues]    Script Date: 06/30/2014 13:04:30 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE procedure [dbo].[sp_getgridvalues] 
@id int,
@type varchar(50)

as
begin
if(@type='Byid')

select id,name,address from gridsession where id=@id
else
select * from gridsession
end

GO