Finding Data binding with Grid view and Drop Down list

Posted by Sanku under ASP.NET on 9/14/2013 | Points: 10 | Views : 2064 | Status : [Member] | Replies : 6
Hi please i am finding difficult in binding drop down list as well as grid view with data from sql. Reason i am using separate class file ,so how to do it.




Responses

Posted by: Allemahesh on: 9/16/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Sanku,

I thing you are using 3 or 4 tier architecture. You will get some idea by using below code.
So you can see the below code:-

Create a class named it as DAL.cs (it will saved in App_code folder). In this dataset we add the namespace Using System.Data;

public DataSet Vacant()

{
SqlConnection con = new SqlConnection(connString);
DataSet ds = new DataSet();
try
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from tname", con);
da.Fill(ds);
return ds; //dataset was returned
}
catch
{
throw;
}
finally
{
ds.Dispose();
con.Close();
con.Dispose();
}
}


Then in the BAL we write the following code for getting the dataset and bind to grid

 public DataSet Vacant()

{
DAL Odal = new DAL();
try
{
return Odal.Vacant();

}
catch
{
throw;
}
finally
{
Odal = null;
}
}


then in the .cs page as follows

 protected void Page_Load(object sender, EventArgs e)

{
BAL Obal = new BAL();
DataSet ds = new DataSet();
try
{
ds = Obal.vacant();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();

}
catch (Exception ex)
{
Response.Write(ex.message);
}
finally
{
Obal = null;
}
}
}


Happy Coding

If it helps you or directs U towards the solution, MARK IT AS ANSWER

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

Posted by: Allemahesh on: 9/16/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can also see the below links :-

http://dotnetsridhar.blogspot.in/2012/04/3-tier-architecture-for-inserting-and.html
http://dotnetsridhar.blogspot.in/2013/04/insert-edit-update-delete-in-gridview.html
http://www.aspdotnet-suresh.com/2012/05/bind-data-to-dropdownlist-in-gridview.html

Happy Coding

If it helps you or directs U towards the solution, MARK IT AS ANSWER

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

Posted by: Kmandapalli on: 9/16/2013 [Member] Silver | Points: 25

Up
0
Down
Hi,

Can you explain clearly what exactly you need?

Regards,
Shree M.

Kavya Shree Mandapalli

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

Posted by: Sanku on: 9/16/2013 [Member] Starter | Points: 25

Up
0
Down
Sir ,
actually i am using 2 tier arch itself and connection form class file to .cs file its making difficult to understand .
thank you for replying

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

Posted by: Allemahesh on: 9/17/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can use the below link:-
http://www.c-sharpcorner.com/uploadfile/gowth/two-tier-and-three-tier-architecture-with-example/
http://www.dotnetfunda.com/forums/thread2361-1-tier-and-2-tier-architecture.aspx

Happy Coding
If it helps you or directs U towards the solution, MARK IT AS ANSWER


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

Posted by: Hornstalk on: 11/11/2013 [Member] Starter | Points: 25

Up
0
Down
GridView data binding in C#.NET,
http://www.kettic.com/winforms_ui/csharp_guide/gridview_populate_data.shtml

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

Login to post response