【问题标题】:Add Title to DataGrid将标题添加到 DataGrid
【发布时间】:2013-05-12 00:31:21
【问题描述】:

我在 aspx 页面上有一个 DataGrid 项目。这些列是通过 Oracle 查询中的 DataSource/DataBind 填充的 BoundColumns。

我要做的是为每个列标题添加一个标题属性

我拥有的是

<asp:datagrid id="DataGrid1" runat="server" OnItemCreated="DataGrid1_ItemCreated">

在其他属性中

然后在创建项目时我有一个 C#.net 事件触发器

protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e){

我发现了如何将标题属性添加到一行,甚至明确地添加标题行,但不知道如何解析单个标题

我一直在使用:

if(e.Item.Cells[0] = "&nbsp;"){
    e.Item.Attributes.Add("title", "Project Title";
}

我还没有找到访问标题文本或行中单个文本值的方法。任何建议表示赞赏,谢谢。

【问题讨论】:

  • 查看 Marc 的回答 here
  • 我没有完全理解您的问题您是要访问标题单元格并更改其中的文本还是要为标题的每个单元格添加一个属性或两者兼而有之?
  • 我想用标题单元格内容为标题的每个单元格添加一个属性。问题是列被定义为 BoundColumns,它不将标题作为属性。我通过在项目创建上附加属性来绕过它。看起来马克的回答应该有助于获取内容,我明天必须检查一下。

标签: c# asp.net .net datagrid boundcolumn


【解决方案1】:

这就是我所做的:

protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e){
    for(int i = 0; i < e.Item.Cells.Count; i++){
        e.Item.Cells[i].Attributes.Add("title", DataGrid1.Columns[i].HeaderText);
    }
}

【讨论】:

    猜你喜欢
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 2021-09-01
    • 2012-02-13
    • 1970-01-01
    • 2016-10-04
    • 2016-06-28
    相关资源
    最近更新 更多