Please See the Attachment.
Dear all members,
I want to Bind DatagridView from database just like my Attachment designed
in Windows Application. C#.
How???? (not manual).
Please Help.
i am using that code.
private void binddata()
{
SqlDataAdapter da = new SqlDataAdapter(@"SELECT distinct Sectiontype + ' ' + '['+ Questiontype + ']' + ' ' + 'Attempt Question :-' + ' ' + Attemptquestion + ' ' + 'Total Marks :-' + ' ' + Totalmarks
as 'Groupst', Question,Fullmarks FROM dbo.tbl_QuestionConfig where Subject='C++'
group by Sectiontype + ' ' + '['+ Questiontype + ']' + ' ' + 'Attempt Question :-' + ' ' +
Attemptquestion + ' ' + 'Total Marks :-' + ' ' + Totalmarks ,Question,Fullmarks", con);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
dataGridView1.AutoGenerateColumns = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.LightSeaGreen;
foreach (DataGridViewRow r in dataGridView1.Rows)
{
r.DefaultCellStyle.BackColor = Color.LightCyan;
}
}
{
SqlDataAdapter da = new SqlDataAdapter(@"SELECT distinct Sectiontype + ' ' + '['+ Questiontype + ']' + ' ' + 'Attempt Question :-' + ' ' + Attemptquestion + ' ' + 'Total Marks :-' + ' ' + Totalmarks
as 'Groupst', Question,Fullmarks FROM dbo.tbl_QuestionConfig where Subject='C++'
group by Sectiontype + ' ' + '['+ Questiontype + ']' + ' ' + 'Attempt Question :-' + ' ' +
Attemptquestion + ' ' + 'Total Marks :-' + ' ' + Totalmarks ,Question,Fullmarks", con);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
dataGridView1.AutoGenerateColumns = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.LightSeaGreen;
foreach (DataGridViewRow r in dataGridView1.Rows)
{
r.DefaultCellStyle.BackColor = Color.LightCyan;
}
}


Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 22, 2016, 9:07 PM EDT
Nirmal RoyRank #4,618 · 334 reputationPosted Aug 22, 2016, 9:16 PM EDT
Manas MohapatraRank #182 · 13.2K reputationPosted Aug 22, 2016, 9:27 PM EDT
Nirmal RoyRank #4,618 · 334 reputationPosted Aug 22, 2016, 9:32 PM EDT
Nirmal RoyRank #4,618 · 334 reputationPosted Aug 22, 2016, 10:58 PM EDT
Midhun TpRank #388 · 6.5K reputationPosted Aug 22, 2016, 11:09 PM EDT
Vinay SinghRank #604 · 4K reputationPosted Aug 23, 2016, 4:15 AM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Aug 23, 2016, 5:50 AM EDT
Ajay MalikRank #752 · 3.1K reputationPosted Aug 23, 2016, 8:02 PM EDT