dnf春节套武器装扮:DataGide绑定数据后页面没有显示

来源:百度文库 编辑:高校问答 时间:2024/05/01 12:25:29
<td width="608">
<div align="center"><ASP:DATAGRID id="MyList" AllowPaging="True" PageSize="20" OnPageIndexChanged="MyList_Page" PagerStyle-Visible="false"
runat="server" AutoGenerateColumns="false" EnableViewState="false" Font-Size="8pt"
Font-Name="宋体" CellSpacing="1" CellPadding="2" ShowFooter="false" GridLines="None" Width="400">
<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" ID="Hyperlink1"/>
<%# DataBinder.Eval(Container.DataItem, "shijian","{0:d}")%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</ASP:DATAGRID></div>
</td>

using System;
using System.Data;
using System.Data.SqlClient ;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace news
{
public class First : Page
{
protected System.Web.UI.WebControls.DataGrid MyList;
protected System.Web.UI.WebControls.DataGrid MyList1;

private void Page_Load(Object sender, EventArgs e)
{

if(!IsPostBack)
{

string connstring="Provider=SQLOLEDB;Data Source=(local); "+"Initial Catalog=ecollege;uid=sa;pwd=; "+"Integrated Security=SSPI; ";
SqlConnection conn=new SqlConnection (connstring);
SqlDataAdapter myCommand = new SqlDataAdapter ("select top 12 contents.* FROM contents WHERE typeid=1 order by shijian desc", conn);
SqlDataAdapter myCommand1= new SqlDataAdapter ("select top 12 contents.* FROM contents WHERE typeid=2 order by shijian desc", conn);
DataSet ds = new DataSet();
myCommand.Fill(ds, "contents");
myCommand1.Fill(ds, "types");
MyList.DataSource = ds.Tables["contents"].DefaultView;
MyList1.DataSource = ds.Tables["types"].DefaultView;
MyList.DataBind();
MyList1.DataBind();
}
}

private void InitializeComponent()
{

}
public void MyList_Page(Object sender, DataGridPageChangedEventArgs e)
{
//由内置页导航使用。CurrentPageIndex 已设置
MyList.CurrentPageIndex = e.NewPageIndex;
DataBind();
}

第一 把表格做成象素单位的 不要做成百分比的
第二 把文字用CSS控制
这样下显示器下就不会改变了
还有
如果里面有层的话 要做绝对层 不要做相对层