1..如何控制DATAGRID生成的行和列的宽度和高度?(具体)
2..帮忙改改:
错误提示:选定数据源上未能找到名称为“mz”的字段或属性。
行 51: xpTable.DataBind();代码:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
xpTable.Attributes.Add("altRowColor","oldlace");
xpTable.Attributes.Add("align","center"); SqlConnection cn=new SqlConnection();
cn.ConnectionString="data source =220.201.132.57;initial catalog=test;persist security info=false;uid=sa;pwd=clsoft;";
cn.Open();
String cnstring ="select top 3 xm,xb,mz AS SubTitle from TABLE1";
SqlCommand cmd=new SqlCommand(cnstring,cn); xpTable.DataSource=cmd.ExecuteReader(CommandBehavior.CloseConnection);
xpTable.DataBind();
cmd.Dispose();
cn.Close();
cn.Dispose();
cn = null;
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
} /// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.xpTable.SelectedIndexChanged += new System.EventHandler(this.xpTable_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void xpTable_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
2..帮忙改改:
错误提示:选定数据源上未能找到名称为“mz”的字段或属性。
行 51: xpTable.DataBind();代码:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
xpTable.Attributes.Add("altRowColor","oldlace");
xpTable.Attributes.Add("align","center"); SqlConnection cn=new SqlConnection();
cn.ConnectionString="data source =220.201.132.57;initial catalog=test;persist security info=false;uid=sa;pwd=clsoft;";
cn.Open();
String cnstring ="select top 3 xm,xb,mz AS SubTitle from TABLE1";
SqlCommand cmd=new SqlCommand(cnstring,cn); xpTable.DataSource=cmd.ExecuteReader(CommandBehavior.CloseConnection);
xpTable.DataBind();
cmd.Dispose();
cn.Close();
cn.Dispose();
cn = null;
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
} /// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.xpTable.SelectedIndexChanged += new System.EventHandler(this.xpTable_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void xpTable_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
mz AS SubTitle
-------------
你应该用SubTitle
<div align="center" style="PADDING-RIGHT:20px; PADDING-LEFT:20px; PADDING-BOTTOM:20px; PADDING-TOP:20px"><b>XP 风格的可拖动列、排序的DataGrid的例子。</b></div>
<asp:DataGrid id="xpTable" runat="server" AutoGenerateColumns="False" Cellpadding="2" BorderWidth="0px"BorderStyle="None" STYLE="BORDER-COLLAPSE:separate" Width="488px" CssClass="xpTable" Height="176px">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="xm" SortExpression="xm" HeaderText="文章标题">
<HeaderStyle Font-Bold="True"></HeaderStyle>
<ItemStyle Height="22px"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="xb" SortExpression="xb" HeaderText="创建日期" DataFormatString="{0:yyyy年MM月dd日 HH:mm:ss}">
<HeaderStyle Font-Bold="True"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="mz" SortExpression="mz" HeaderText="所属栏目">
<HeaderStyle Font-Bold="True"></HeaderStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid></form>
datagrid的属性
把这个里面的mz改成SubTitle
你不是在sql语句中,把这个给代替了吗?