C# 将 Telerik RadGRID 绑定到 list<string> 对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/547878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Binding Telerik RadGRID to a list<string> object
提问by alchemical
I have a simple use for RadGrid that involves binding it to a list of strings
我对 RadGrid 有一个简单的使用,它涉及将它绑定到一个字符串列表
i.e. using: list<string>
The bind works OK and the data displays in the grid. However, the header says "Item", and there are other aspects of the column I'd like to be able to customize. I've tried to set the "DataField" property of the column on the ascx page:
绑定工作正常,数据显示在网格中。但是,标题显示“项目”,并且我希望能够自定义该列的其他方面。我试图在 ascx 页面上设置列的“DataField”属性:
<telerik:GridTemplateColumn UniqueName="column"
DataField="" HeaderText="Omniture Codes">
however, it seems to want the name of a data field, as in what you would get with a datatable object, but not with a list.
但是,它似乎需要数据字段的名称,就像使用数据表对象而不是列表一样。
Does anyone know a way to bind the column to the list, or have another idea for a work-around?
有谁知道将列绑定到列表的方法,或者有其他解决方法的想法?
采纳答案by M4N
I think you should use a GridBoundColumn instead of the GridTemplateColumn and disable AutoGenerateColumns.
我认为您应该使用 GridBoundColumn 而不是 GridTemplateColumn 并禁用 AutoGenerateColumns。
E.g. the following works for me:
例如以下对我有用:
ASPX:
ASPX:
<telerik:RadGrid ID="grid" runat="server" AutoGenerateColumns="false">
<MasterTableView>
<Columns>
<telerik:GridBoundColumn DataField="" HeaderText="MyHeaderText">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
Code-behind:
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
List<string> data = new List<string> {"a", "b", "c"};
grid.DataSource = data;
}
回答by GregD
You have to try something like this with the RadGrid:
你必须用 RadGrid 尝试这样的事情:
<Columns>
<telerik:GridBoundColumn DataField="AddrLine1" HeaderText="Address Line 1" SortExpression="AddrLine1" UniqueName="AddrLine1">
<HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" Wrap="True" />
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"Font-Underline="False" HorizontalAlign="Left" Wrap="True" />
</telerik:GridBoundColumn>
</Columns>
回答by dankyy1
you may also use Item Template property of radgrid to generate any desgin..
您还可以使用 radgrid 的项目模板属性来生成任何设计..
like
喜欢
<ItemTemplate>
<div style="width:277px; text-align:left;">
<span style=" font-size:11px;"> Tdata1:</span>
<%# Eval("data1")%>
<br />
<span> data2:</span>
<%# Eval("data2")%>
<br />
</div>
</ItemTemplate>
<Columns>
<telerik:GridBoundColumn DataField="data1" HeaderText="data1" SortExpression="data1" UniqueName="data1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="data2" HeaderText="data2" SortExpression="data2" UniqueName="data2">
</telerik:GridBoundColumn>
</Columns>