ASPxGridView,了Itemplate,和eval [英] ASPxGridView, ITemplate, and Eval

查看:412
本文介绍了ASPxGridView,了Itemplate,和eval的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何创建一个AXPxGridViewDataTextColumn在 C#模板,没有任何标记,并使用eval显示DataItem的价值?

How can I create a template in c# for an AXPxGridViewDataTextColumn without any markup and with using Eval to display the DataItem value?

这是我有-The问题是,字符串<%#的eval(dataTableField1)%>在GridView显示出来的每一行,而不是适当的值。

-The problem that I am having is that the string "<%#Eval("dataTableField1")%>" shows up in the GridView for every row instead of the appropriate values.

下面是我尝试的例子:

    public override void DataBind()
    {
        ...
        GridViewDataTextColumn myCol = new GridViewDataTextColumn();
        myCol.Caption = "col1";
        myCol.FieldName = "dataTableField1";
        myCol.DataItemTemplate = new ColumnDataItemTemplate();
        theGridView.Columns.Clear();
        theGridView.Columns.Add(myCol);
        theGridView.DataSource = AdjustDataSource();
        theGridView.DataBind();
        ...
    }

    public class ColumnDataItemTemplate : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            GridViewDataItemTemplateContainer Container = (container as GridViewDataItemTemplateContainer);
            LiteralControl lit = new LiteralControl("<div id=\"hr\" style=\"height:100%\"><%#Eval(\"dataTableField1\")%></div>");
            Container.Controls.Add(lit);
        }
    }

下面是什么,我想从这个的链接

Here is an example of what I want to do with the row height taken from this link:

<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="3">
    <DataItemTemplate>
        <div id="hr" style="height:100%">
            <%#Eval("Description")%>
        </div>
    </DataItemTemplate>
</dx:GridViewDataTextColumn>

文档链接显示使用模板类似的例子在标记,但我想这样做在code的后面。

This documentation link shows similar examples of using templates in the markup but I want to do it in the code behind.

下面是一个链接模板。

由于提前,

Soenhay

编辑:
我能得到的第一个元素正确的模板分配移动到CustomColumnDisplayText事件,但在ASPxGridView显示的所有其他元素显示显示评估和演示字符串。

I was able to get the first element to properly display by moving the template assignment to the CustomColumnDisplayText event but all other elements displayed in the ASPxGridView show the Eval string.

推荐答案

我有其他2解决方案,但我把他们赶走,因为我认为这是最好的(我将是任何其他建议/改进感激):

I had 2 other solutions but I removed them as I think this is the best ( I would be grateful for any other suggestions/improvements ):

        public override void DataBind()
        {
             ...
             GridViewDataTextColumn myCol = new GridViewDataTextColumn();
             myCol.Caption = "col1";
             myCol.FieldName = "dataTableField1";
             myCol.DataItemTemplate = new ColumnDataItemTemplate();
             theGridView.Columns.Clear();
             theGridView.Columns.Add(myCol);
             theGridView.DataSource = AdjustDataSource();
             theGridView.DataBind();
             ...
        }

        public class ColumnDataItemTemplate : ITemplate
        {
            public void InstantiateIn(Control container)
            {
                GridViewDataItemTemplateContainer Container = (container as GridViewDataItemTemplateContainer);
                LiteralControl lit = new LiteralControl("<div id='hr' style='height:100%; font-size:x-large;'>" + DataBinder.Eval(Container.DataItem, Container.Column.FieldName) + "</div>");
                Container.Controls.Add(lit);
            }
        }

目前<一个href=\"http://help.devex$p$pss.com/#AspNet/DevEx$p$pssWebASPxGridViewASPxGridView_CustomColumnDisplayTexttopic\"相对=nofollow>链接我找到了一个理由,不使用事件:
该事件CustomColumnDisplayText不应该为模板的列进行处理。

At this link I have found a reason to not use the event: "The CustomColumnDisplayText event should not be handled for template columns. "

这<一个href=\"http://documentation.devex$p$pss.com/#AspNet/DevEx$p$pssWebASPxGridViewGridViewDataColumn_DataItemTemplatetopic\"相对=nofollow>链接帮助与DataBinder.Eval的一部分。

This link helped with the DataBinder.Eval part.

这篇关于ASPxGridView,了Itemplate,和eval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆