• 全部
  • .NET Framework
  • ASP
  • Web Services
  • .NET互联网桌面应用
  • VB
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • AppLauncher
  • 问答

程序生成DataGrid,DataGrid中需要使用TemplateColumn、HyperLinkColumn

david2745 2004-11-04 11:48:34
查询结果生成的DataTable,列不定,用DataGrid显示,需要用到TemplateColumn、HyperLinkColumn
...全文
168 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
brightheroes 2004-11-04
HyperLinkColumn一样可以用模板列实现
回复
brightheroes 2004-11-04
/// <summary>
/// 实现ITemplate接口,用来打印
/// </summary>
public class ColumnTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
LinkButton lb = new LinkButton();
lb.Text = "打印";
lb.CommandName = "Print";
container.Controls.Add(lb);
}
}

/// <summary>
/// 实现ITemplate接口,用来导出
/// </summary>
public class ColumnTemplateExport : ITemplate
{
public void InstantiateIn(Control container)
{
LinkButton lb = new LinkButton();
lb.Text = "导出";
lb.CommandName = "Export";
container.Controls.Add(lb);
}
}
回复
brightheroes 2004-11-04
/// <summary>
/// 清空GRID的COLUMN
/// </summary>
/// <param name="vardg"></param>
private static void RefreshGrid(DataGrid vardg)
{
vardg.Columns.Clear();

BoundColumn dc = new BoundColumn();
dc.HeaderText = "ID";
dc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
dc.DataField = "ID";
dc.Visible = false;
dc.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
vardg.Columns.AddAt(0,dc);

dc = new BoundColumn();
dc.HeaderText = "序号";
dc.HeaderStyle.Wrap = false;
dc.HeaderStyle.Width = 30;
dc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
dc.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
vardg.Columns.AddAt(1,dc);
}

/// <summary>
/// 创建按专家打印的GRID
/// </summary>
/// <param name="vardg"></param>
private static void CreateExpertDataGrid(DataGrid vardg)
{
RefreshGrid(vardg);

BoundColumn dc = new BoundColumn();
dc.HeaderText = "专家姓名";
dc.HeaderStyle.Wrap = false;
dc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
dc.DataField = "EXPERT_NAME";
dc.SortExpression = "EXPERT_NAME";
dc.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
vardg.Columns.AddAt(2,dc);

dc = new BoundColumn();
dc.HeaderText = "所属医院";
dc.HeaderStyle.Wrap = false;
dc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
dc.DataField = "HOSPITAL";
dc.SortExpression = "HOSPITAL";
vardg.Columns.AddAt(3,dc);

TemplateColumn tc = new TemplateColumn();
tc.ItemTemplate = new ColumnTemplate();
tc.HeaderText = "打印";
dc.HeaderStyle.Wrap = false;
tc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
tc.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
tc.HeaderStyle.Width = 30;
vardg.Columns.AddAt(4,tc);

tc = new TemplateColumn();
tc.ItemTemplate = new ColumnTemplateExport();
tc.HeaderText = "导出";
dc.HeaderStyle.Wrap = false;
tc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
tc.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
tc.HeaderStyle.Width = 30;
vardg.Columns.AddAt(5,tc);
}
回复
david2745 2004-11-04
如何用程序添加TemplateColumn、HyperLinkColumn?有例子程序吗?
回复
孟子E章 2004-11-04
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchtopquestionsaboutaspnetdatagridservercontrol.asp
回复
WeeklyQLR 2004-11-04
在datagrid中添加模块,设置TemplateColumn、HyperLinkColumn!
回复
red9152 2004-11-04
我也需要,帮你顶
回复
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2004-11-04 11:48
社区公告
暂无公告