Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
C#
public class Candidate
{
    public  int CandidateId {get;set;}
    public string CName { get; set; }
    public string CFName { get; set; }
    public string CMName { get; set; }
    public string CSex { get; set; }
    public string CLanguageknown { get; set; }
    public DateTime CDob { get; set; }
    
    public DataTable getcandidate()
    {
       SqlConnection con = new SqlConnection(@"Data Source=KALAISELVAN\SQLEXPRESS;Initial Catalog=Applicant;Integrated Security=True");
       SqlCommand cmd = new SqlCommand("select * from candidate", con);
       DataTable dt = new DataTable();
       SqlDataAdapter da = new SqlDataAdapter(cmd);
       da.Fill(dt);
       return dt;
    }

this is class file i have created . Now i wana to load gridview values in my form load . How can i write.
C#
private void Form1_Load(object sender, EventArgs e)
{
   Candidate cand = new Candidate();
   cand.getcandidate();
}

in form load i have written this, after that i don't know how can bind values.. ? If any one know plz guide me

Thanks,
Posted
Updated 9-Jun-15 2:13am
v2

1 solution

If you want to bind DataTable returned by getcandidate method -

GridView1.DataSource = cand.getcandidate();
GridView1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900