有一个页面,使用了母版,具体代码如下:
<asp:Content ID="Content" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:GridView ID="GridView" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
Height="171px" Width="581px">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</asp:Content>就是这个Content里放了一个gridview,我CS代码里判断数据库数据是否存在,如果存在,绑定到gridview,如果不存在,输出 数据为空。
我用Response.write输出,怎么在出来的HTML页面最上边,不在这个Content里。可以直接往Content里输出文字么?
cs代码:
public partial class ManageSystem_signup : System.Web.UI.Page
{
private string connstr = "";
private string sql = "select * from business";
protected void Page_Load(object sender, EventArgs e)
{
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Request.PhysicalApplicationPath + ConfigurationManager.ConnectionStrings["conn"].ToString() + ";User Id=;Password=;";
OleDbConnection conn = new OleDbConnection(connstr);
OleDbCommand cmd = new OleDbCommand(sql,conn);
conn.Open();
OleDbDataReader odr = cmd.ExecuteReader();
if (odr.HasRows)
{
this.GridView.DataSource = odr;
this.GridView.DataBind();
odr.Close();
conn.Close();
}
else
{
Response.Write("<table><tr><td>暂时没有数据。</td></tr></table>");
}
}
}
<asp:Content ID="Content" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:GridView ID="GridView" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
Height="171px" Width="581px">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</asp:Content>就是这个Content里放了一个gridview,我CS代码里判断数据库数据是否存在,如果存在,绑定到gridview,如果不存在,输出 数据为空。
我用Response.write输出,怎么在出来的HTML页面最上边,不在这个Content里。可以直接往Content里输出文字么?
cs代码:
public partial class ManageSystem_signup : System.Web.UI.Page
{
private string connstr = "";
private string sql = "select * from business";
protected void Page_Load(object sender, EventArgs e)
{
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Request.PhysicalApplicationPath + ConfigurationManager.ConnectionStrings["conn"].ToString() + ";User Id=;Password=;";
OleDbConnection conn = new OleDbConnection(connstr);
OleDbCommand cmd = new OleDbCommand(sql,conn);
conn.Open();
OleDbDataReader odr = cmd.ExecuteReader();
if (odr.HasRows)
{
this.GridView.DataSource = odr;
this.GridView.DataBind();
odr.Close();
conn.Close();
}
else
{
Response.Write("<table><tr><td>暂时没有数据。</td></tr></table>");
}
}
}
你可以在一gridview下面放一个隐藏的label嘛,当没有数据的时间就显示嘛.应该,gridview有一个属性叫EmptyDataText,用于设置当没有数据的时候显示的字符串.如下:<asp:gridview runat="server" CellPadding="4" ForeColor="#333333" GridLines="Horizontal" EmptyDataText="没有找到相关数据……" >
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="White" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="White" ForeColor="#2461BF" HorizontalAlign="Left" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<PagerSettings FirstPageText="&lt;首页&gt;" LastPageText="&lt;末页&gt;" Mode="NumericFirstLast" NextPageText="下一页>>" PreviousPageText="<<上一页" />
</asp:gridview>