how to bind the data to gridview in 3-tier [Resolved]

Posted by Kusuma under ASP.NET on 1/31/2013 | Points: 10 | Views : 11271 | Status : [Member] | Replies : 3
hii

I have taken a gridview, in this just want to bind the data in 3-tier.
Pls help in this..

Thanks,
kusuma.




Responses

Posted by: Ankitsrist on: 2/4/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
hey kusuma,
firstly put this code in your business access layer(bal) class
create objects for classes
//dal da=new dal();
//bal ba=new bal();

public DataTable load()

{

dal da = new dal();
return da.load();

}


data access layer(dal) code

public DataTable load()

{
db.mycon();

bol bo = new bol();

bal ba = new bal();

SqlDataAdapter adp = new SqlDataAdapter("sample_dml_proc", db.con);
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
adp.SelectCommand.Parameters.Add("@status", SqlDbType.VarChar).Value = "display";
DataSet ds = new DataSet();
adp.Fill(ds, "table1");
return ds.Tables["table1"];

}[


default.aspx.cs

 public DataTable gridv()

{
db.mycon();
bal ba = new bal();
DataTable dt = new DataTable();
dt= ba.load();
return dt;

}
public void fillgrid()
{
db.mycon();
GridView1.DataSource = gridv();
GridView1.DataBind();

}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
fillgrid();

}

}


change according to ur need

mark if this help u

Kusuma, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 1/31/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Gridview
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;

protected void Page_Load(object sender, EventArgs e)
{
bindgrid();
}
private void bindgrid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "employee");
g1.DataMember = "employee";
g1.DataSource = ds;
g1.DataBind();

con.Close();
}


}
}


If this post helps you mark it as answer
Thanks

Kusuma, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kusumas on: 2/1/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Kusuma,

Please refer below mentioned link this will help you.
In this article very useful explanation from Shoe Narayan..

http://www.dotnetfunda.com/articles/article71.aspx




Kusuma, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response