Nirmal Roy

Nirmal Roy

  • NA
  • 365
  • 29.2k

Datagrid Bind error

Aug 23 2016 9:06 AM
private void bindfunction()<br /> {<br /> int i = 0; int j=0;<br /> SqlDataAdapter da = new SqlDataAdapter(@"select distinct Sectiontype, Questiontype,Subject from dbo.tbl_QuestionConfig where Subject='C++'", con);<br /> DataTable dt = new DataTable();<br /> da.Fill(dt);<br /> if (dt.Rows.Count &gt; 0)<br /> {<br /> for (i = 0, j = 0; i &lt; dataRepeater1.ItemCount &amp;&amp; j &lt; dt.Rows.Count; i++,j++)<br /> {<br /><br /> // Label txtExample = (Label)dataRepeater1.Controls.Find("label1", true).First();<br /> //if (txtExample != null)<br /> //{<br /> SqlDataAdapter daa = new SqlDataAdapter(@"select Question,Fullmarks from dbo.tbl_QuestionConfig where Sectiontype='" + dt.Rows[i]["Sectiontype"].ToString() + "' and Questiontype='" + dt.Rows[i]["Questiontype"].ToString() + "' and Subject='" + dt.Rows[i]["Subject"].ToString() + "'", con);<br /> DataTable dtt = new DataTable();<br /> daa.Fill(dtt);<br /> dataGridView1.DataSource = dtt;<br /> dataGridView1.AutoGenerateColumns = false;<br /> dataGridView1.EnableHeadersVisualStyles = false;<br /> dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.LightSeaGreen;<br /> foreach (DataGridViewRow r in dataGridView1.Rows)<br /> {<br /> r.DefaultCellStyle.BackColor = Color.LightCyan;<br /> }<br /> <br /> }<br /> }<br /> <br /><div> }</div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp;frist time page load datagrid is null ?? no data found in datagrid in widows application.</div><div>&nbsp;</div><div>&nbsp;</div>

Answers (7)