C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET GridView »

Generic Code


Posted Date: 28 Sep 2009    Resource Type: Code Snippets    Category: ASP.NET GridView
Author: palaniellappankMember Level: Silver    
Rating: 1 out of 5Points: 7



This code shows sample use of generic

code behind

BusinessClass Obj = new BusinessClass();

List people = new List();
//people = new BusinessClass().LoadThroughDataTable();
people = Obj.LoadThroughDataTable();
grdStatus.DataSource = people;
grdStatus.DataBind();


class file


public string event_id { get; set; }
public string date_start { get; set; }
public string event_name { get; set; }
public string location_url { get; set; }
public int event_id1 { get; set; }
public DateTime date_start1 { get; set; }
public string event_name1 { get; set; }
public string location_url1 { get; set; }

public List LoadThroughDataTable()
{
var list = new List();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CONSTR"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("select event_id,date_start,event_name,location_url from events", conn))
{
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
DataTable table = new DataTable();
conn.Open(); // open the connection
ad.Fill(table);
conn.Close(); // close the connection
// loop through all rows
foreach (DataRow row in table.Rows)
{

BusinessClass p = new BusinessClass()
{
event_id = row["event_id"].ToString(),
date_start = row["date_start"].ToString(),
event_name = row["event_name"].ToString(),
location_url = row["location_url"].ToString()

};
list.Add(p);
}
}
}
return list;
}
}


For more details, visit http://www.dotnetfunda.com/articles/article472-passing-data-between-layers-using-generic-list-collection.aspx



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Generic Code  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Bulleted list
Previous Resource: getting value of invisible boundfield in gridview - (vbscript)
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use