Hi friends
The below is my code for binding data to gridview.
This method for creating datagridview column
public void designgrid()
{
DataGridViewColumn firstcolumn=dataGridView1.Columns[1];
DataGridViewCell cell=new DataGridViewTextBoxCell();
firstcolumn.CellTemplate=cell;
firstcolumn.HeaderText = "AdmissionNumber";
firstcolumn.Width = 50;
DataGridViewColumn secondcolumn = dataGridView1.Columns[2];
DataGridViewCell cell1 = new DataGridViewTextBoxCell();
secondcolumn.CellTemplate = cell1;
secondcolumn.HeaderText = "StudentName";
secondcolumn.Width = 80;
DataGridViewColumn Thirdcolumn = dataGridView1.Columns[3];
DataGridViewCell cell2 = new DataGridViewTextBoxCell();
Thirdcolumn.CellTemplate = cell1;
Thirdcolumn.HeaderText = "StanderedName";
Thirdcolumn.Width = 80;
DataGridViewColumn forthcolumn = dataGridView1.Columns[4];
DataGridViewCell cell3 = new DataGridViewTextBoxCell();
forthcolumn.CellTemplate = cell3;
forthcolumn.HeaderText = "RegisterNumber";
forthcolumn.Width = 50;
DataGridViewColumn fifthcolumn = dataGridView1.Columns[5];
fifthcolumn = new DataGridViewComboBoxColumn();
fifthcolumn.HeaderText = "SortNo";
fifthcolumn.Width = 50;
}
This code for binding data to gridview
DataTable studentbind = ibl4.studentbindforfemale(sdt);
int rowcount = studentbind.Rows.Count;
List<string> no = ibl4.setnoofint(rowcount);
int registerno = ibl4.getregiter(sdt);
designgrid();
for(int i=0;i<rowcount;i++)
{
dataGridView1.Rows[i].Cells[0].Value = studentbind.Rows[i]["AdmissionNumber"].ToString();
dataGridView1.Rows[i].Cells[1].Value = studentbind.Rows[i]["StudentName"].ToString();
dataGridView1.Rows[i].Cells[2].Value = studentbind.Rows[i]["Standered_name"].ToString();
dataGridView1.Rows[i].Cells[3].Value = registerno;
}
Here "Datatable studentbind" contains first 3 columns value as specified in the name in code.
fourth column is textbox column which acutally add as a extra column that want to contain the value of "Registerno" for all row.
fithcolumn i have created as a combobox column. but i dont know how can bind data to this column. the bind data is "List<string> no";
and also please help how can add data to gridviewtextboxcolumn.
still i didnt run my code. so i dont know whether is in the code. if error come please help me to solve the problem