页面是<asp:GridView ID="GridView1" runat="server" DataKeyNames="CatalogId" GridLines=none Width="100%">
<Columns>
<asp:TemplateField HeaderText="类别编号">
<ItemTemplate><asp:Label ID="Label2" runat="server" Text='<%# Bind("CatalogId") %>'></asp:Label></ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="类别名称">
<ItemTemplate><asp:Label ID="Label1" runat="server" Text='<%# Bind("CatalogName") %>'></asp:Label></ItemTemplate>
<ItemStyle HorizontalAlign=Left />
</asp:TemplateField>
</Columns>
<RowStyle/>
<SelectedRowStyle />
<HeaderStyle CssClass="tabletitle"/>
</asp:GridView>cs文件是public partial class Admin_News_NewsCatalogs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGridView();
}
} //绑定新闻类别列表
private void BindGridView()
{
OleDbConnection MyConn;
MyConn = new OleDbConnection(ConfigurationManager.AppSettings["myconnstring"].ToString() + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["mydbpath"]));
MyConn.Open();
string cmdText = "select * from NewsCatalogs order by CatalogId asc";
OleDbDataAdapter da = new OleDbDataAdapter(cmdText, MyConn);
DataSet ds = new DataSet();
da.Fill(ds, "NewsCatalogs");
GridView1.DataSource = ds.Tables["NewsCatalogs"].DefaultView;
GridView1.DataBind();
RecordCount.Text = ds.Tables[0].Rows.Count.ToString();
}
}为什么显示出来是这样的
类别编号 类别名称 CatalogId CatalogName eCatalogName title
1 最新新闻 1 最新新闻
10 新闻动态 10 新闻动态
11 行业新闻 11 行业新闻 就后面四列都不是我要的,什么原因啊
<Columns>
<asp:TemplateField HeaderText="类别编号">
<ItemTemplate><asp:Label ID="Label2" runat="server" Text='<%# Bind("CatalogId") %>'></asp:Label></ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="类别名称">
<ItemTemplate><asp:Label ID="Label1" runat="server" Text='<%# Bind("CatalogName") %>'></asp:Label></ItemTemplate>
<ItemStyle HorizontalAlign=Left />
</asp:TemplateField>
</Columns>
<RowStyle/>
<SelectedRowStyle />
<HeaderStyle CssClass="tabletitle"/>
</asp:GridView>cs文件是public partial class Admin_News_NewsCatalogs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGridView();
}
} //绑定新闻类别列表
private void BindGridView()
{
OleDbConnection MyConn;
MyConn = new OleDbConnection(ConfigurationManager.AppSettings["myconnstring"].ToString() + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["mydbpath"]));
MyConn.Open();
string cmdText = "select * from NewsCatalogs order by CatalogId asc";
OleDbDataAdapter da = new OleDbDataAdapter(cmdText, MyConn);
DataSet ds = new DataSet();
da.Fill(ds, "NewsCatalogs");
GridView1.DataSource = ds.Tables["NewsCatalogs"].DefaultView;
GridView1.DataBind();
RecordCount.Text = ds.Tables[0].Rows.Count.ToString();
}
}为什么显示出来是这样的
类别编号 类别名称 CatalogId CatalogName eCatalogName title
1 最新新闻 1 最新新闻
10 新闻动态 10 新闻动态
11 行业新闻 11 行业新闻 就后面四列都不是我要的,什么原因啊
这句加到gridview里
哦,可以了,
对了,如果我把sql改为select CatalogId,CatalogName from NewsCatalogs order by CatalogId asc这样的话,然后不加autogeneratecolumns="false" 他也会显示两次,为什么咧