问题是这样的:
今天从网上弄了一网站代码,IIS运行一切正常。于是想自己做一下。
打开VS编写完了第一部分。发现运行后存在问题:
当我的HTML中放置DataGrid的代码后在设计窗体内可以正常显示DataGrid的外形。运行调试一切OK。
但是显示出的网页却无法从数据库中提取文件,DataGrid处于空白状态。
于是我打开原文件,我将原<html>……</html>的所有内容覆盖了我自己做的。但是显示内容也是如此。
两个default.aspx的区别只有第一行黄色的字不同。
我编写的:(由系统自己生成)(我的命名空间:Newstest 类名MyCodeBehind)
<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="Newstest.MyCodeBehind" %>
原文件:(原来的文件)
<%@ Page Inherits="www.MyCodeBehind" Src="www.cs" %> 以下是HTML中DataGrid的段落:<ASP:DataGrid id="MyList" runat="server" Width="400" GridLines="None" ShowFooter="false" CellPadding="2" CellSpacing="1" Font-Name="宋体" Font-Size="8pt" EnableViewState="false" AutoGenerateColumns="false">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink Text='<%# FormatString(DataBinder.Eval(Container.DataItem,"biaoti").ToString())%>' NavigateUrl='<%# "javascript:newwin(\"shownews.aspx?id="+DataBinder.Eval(Container.DataItem,"id").ToString()+"\");" %>' runat="server"/>
<%# DataBinder.Eval(Container.DataItem, "shijian","{0:d}")%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</ASP:DataGrid>
现在不理解为什么会出现这种情况 !
数据库我采用ACCESS,数据库我是COPY原来的文件的。而且我把其他的文件(除了我建立的那个)COPY到我建立的文件目录下。其他文件都运行正常。

解决方案 »

  1.   

    using System; 
    using System.Data; 
    using System.Data.OleDb; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.HtmlControls; namespace Newstest
    {
    /// <summary>
    /// MyCodeBehind 的摘要说明。
    /// </summary>
    public class MyCodeBehind : Page {
    protected System.Web.UI.WebControls.DataGrid MyList;
    protected System.Web.UI.WebControls.DataGrid MyList1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    { OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ Server.MapPath("new.mdb"));   
    OleDbDataAdapter myCommand = new  OleDbDataAdapter("select top 12 aa.* FROM aa WHERE typeid=1 order by shijian desc", myConnection);
                    OleDbDataAdapter myCommand1 = new  OleDbDataAdapter("select top 12 aa.* FROM aa WHERE typeid=2 order by shijian desc", myConnection);

    DataSet ds = new DataSet();
    myCommand.Fill(ds, "aa");
        myCommand1.Fill(ds, "bb"); MyList.DataSource = ds.Tables["aa"].DefaultView;
    MyList1.DataSource = ds.Tables["bb"].DefaultView;
    MyList.DataBind();
    MyList1.DataBind();
    }// 在此处放置用户代码以初始化页面
    }
    protected string FormatString(string str)
    {
    str=str.Replace("","&nbsp;&nbsp;");
    str=str.Replace("<","&lt");
    str=str.Replace(">","&gt");
    str=str.Replace('\n'.ToString(),"<br>");
    return str;
    } }
    }
      

  2.   

    是这个吗?MyList.DataBind();
    MyList1.DataBind();
      

  3.   

    来晚了,对不起了,我是说像datagrid样的添加个绑定列
    http://chs.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datalist/doc_datalist.aspx