这个问题的出现有些大但逻辑很简单所以请阅读一次。我使用以下代码在gridview中显示输出。
protected void Button1_Click(object sender, EventArgs e)
{
int colcount = 0;
MySqlConnection conMySQL = new MySqlConnection(connString);
conMySQL.Open();
string k = "select subject from class_subject where standard='" + DropDownList3.SelectedItem.Value+"';";
MySqlDataAdapter da = new MySqlDataAdapter(k, conMySQL);
DataTable dt = new DataTable();
da.Fill(dt);
StringBuilder sb = new StringBuilder();
Session["columncount"] = dt.Columns.Count;
for (int count = 0; count < dt.Rows.Count; count++)
{
sb.Append("'0' as '");
sb.Append(dt.Rows[count][0].ToString());
sb.Append("'");
if (count < dt.Rows.Count - 1)
{
sb.Append(",");
}
colcount++;
}
//Label1.Text = sb.ToString();
string qr = "select Admission_num,name,'"+DropDownList3.SelectedItem.Text+"' as Standard,'"+DropDownList1.SelectedItem.Text+"' as Fyear,'"+DropDownList2.SelectedItem.Text+"' as Type_Of_Exam," + sb.ToString() + " from student_data where Admission_Num='" + txt1.Text + "' and Completed_status='running';";
MySqlCommand cmd = new MySqlCommand(qr, conMySQL);
StringBuilder sb1 = new StringBuilder();
MySqlDataAdapter ada = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
ada.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
//foreach (GridViewRow g1 in GridView1.Rows)
//{
// TextBox TextBox1 = new TextBox();
// for (int j = 0; j < 11; j++)
// {
// //GridView1.Rows[0].Cells[j].Controls.Add(TextBox1);
// //g1.Cells[j].Controls.Add(TextBox1);
// if (j > 4)
// {
// TableCell cell = g1.Cells[j];
// cell.Controls.Clear();
// //create a textbox and add it to the cell
// TextBox txt = new TextBox();
// txt.Text = cell.Text;
// cell.Controls.Add(txt);
// }
// }
//}
}
然后我得到了输出
当我在上面的程序中删除评论标签时,我得到了类似的输出
为什么没有显示科学、社会、泰卢固语科目。在此先感谢..
我的 HTML 代码是:
<asp:GridView ID="GridView1" runat="server" ViewStateMode="Disabled"
>
</asp:GridView>