gridview 如何去除相同列
我在窗体中拖入了一个gridview,没做任何设置,在HTML code中加入了两列,
<Columns>
<asp:BoundField DataField="考号" HeaderText="考号" ReadOnly="True" SortExpression="考号" />
<asp:TemplateField HeaderText="学科">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Width="50px" onkeydown="enterNext(this)"> </asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
在c#代码中,使用如下语句进行绑定,
OleDbConnection oleDbConnection1 = new ();这儿的内容我不具体写了,
string str = "select 考号," + xuekeDropDownList.SelectedItem.Text + " from score2008 where 年级=" + nianjiDropDownList.SelectedItem.Value;
oleDbConnection1.Open();
OleDbDataAdapter thisadpter = new OleDbDataAdapter(str, oleDbConnection1);
DataSet dataset = new DataSet();
thisadpter.Fill(dataset, "score2008");
oleDbConnection1.Close();
GridView1.DataSource= dataset.Tables["score2008"];
GridView1.DataBind();
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
TextBox tb = (TextBox)GridView1.Rows[i].FindControl("TextBox2");
tb.Text = dataset.Tables["score2008"].Rows[i][""+xuekeDropDownList.SelectedItem.Text+""].ToString();
}
运行后,显示出来的是四列,前两列和后两列一样,但显示列数去为2,为什么吗,如何取消后两列相同的内容,只显示前两列我加入的内容?
------解决方案--------------------
加上AutoGenerateColumns="false"