How to Bind Combox with Gridview from Database in windows application -C#

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 1256
How to Bind Combox with Gridview from Database in windows application -C#
=========================================================
SqlConnection sqlcon = new SqlConnection("data source=YourPc;initial catalog=Test;user id=sa;password=yourpwd;Integrated Security=false;");

private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = getdata();
DataGridViewComboBoxColumn combo1 = new DataGridViewComboBoxColumn();
combo1.HeaderText = "Country";

for(int i=0;i<=dt.Rows.Count-1 ;i++)
{
combo1.Items.Add(dt.DefaultView[i][0].ToString());
}
dataGridView1.Columns.Add(combo1);
}
public DataTable getdata()
{
DataTable dt = new DataTable();
sqlcon.Open();
SqlDataAdapter sqlcmd = new SqlDataAdapter("Select * from Tbl_Name", sqlcon);
sqlcmd.Fill(dt);
return dt;
}

Comments or Responses

Login to post response