在RadGrid中,我们如何合并2个数据列仅用于查看,但仍然能够单独编辑它们?
我有一个 Telerik 的 RadGrid,它有 2 列,如下所示:
<Columns>
<telerik:GridBoundColumn HeaderText="AirlineCode" UniqueName="AirlineCode" DataField="airlineCode" />
<telerik:GridBoundColumn HeaderText="FlightNumber " EditFormColumnIndex="1" DataField="flightNumber" />
...
...
... more code, but unrelevant to the question here.
</Columns>
我正在相关 NeedDataSource() 函数中提供两列的数据。
所以它正确地呈现如下:
| AirlineCode | FlightNumber |
------------------------------------------
| Delta | 2393 |
| Southwest | 345 |
但现在我的要求发生了一些变化。
为了查看,我想将它们合并在一起并像这样显示:
| Flight |
--------------------------
| Delta-2393 |
| Southwest-345 |
但是,在编辑行时,用户应该能够单独编辑“航空公司代码”和“航班号”。并且这些值仍应正确维护在数据源中。
我知道如果我们希望用户以不同的方式“查看”和“编辑”,我们就必须使用 .
所以我正在尝试这样的事情:
<Columns>
<telerik:GridTemplateColumn EditFormColumnIndex="0" HeaderText="Flight">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "airlineCode")%>
<asp:Literal runat="server" Text="-"></asp:Literal>
<%#DataBinder.Eval(Container.DataItem, "flightNumber")%>
</ItemTemplate>
<EditItemTemplate>
<telerik:GridBoundColumn HeaderText="AirlineCode" UniqueName="AirlineCode" DataField="airlineCode" />
<telerik:GridBoundColumn HeaderText="FlightNumber " EditFormColumnIndex="1" DataField="flightNumber" />
</EditItemTemplate>
</telerik:GridTemplateColumn> ...
...
... more code, but unrelevant to the question here.
</Columns>
但它不起作用。
里面的这两行给出警告:
元素“GridBoundColumn”不是已知元素。如果网站中存在编译错误或 web.config 文件丢失,则可能会发生这种情况。
也许我做错了。需要帮助。
任何帮助表示赞赏。
I have a Telerik's RadGrid which has 2 columns like this:
<Columns>
<telerik:GridBoundColumn HeaderText="AirlineCode" UniqueName="AirlineCode" DataField="airlineCode" />
<telerik:GridBoundColumn HeaderText="FlightNumber " EditFormColumnIndex="1" DataField="flightNumber" />
...
...
... more code, but unrelevant to the question here.
</Columns>
I am supplying the data for both columns in the relevant NeedDataSource() function.
So it renders correctly like this:
| AirlineCode | FlightNumber |
------------------------------------------
| Delta | 2393 |
| Southwest | 345 |
But now my requirement has changed a little bit.
For viewing, I want to merge them together and show it like this:
| Flight |
--------------------------
| Delta-2393 |
| Southwest-345 |
However, while editing the rows the user should be able to edit "AirlineCode" and "Flight Number" separately. And the values should still be correctly maintained in the datasource.
I know that if we want the user to "View" and "Edit" differently, we would have to use .
So I am trying something like this:
<Columns>
<telerik:GridTemplateColumn EditFormColumnIndex="0" HeaderText="Flight">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "airlineCode")%>
<asp:Literal runat="server" Text="-"></asp:Literal>
<%#DataBinder.Eval(Container.DataItem, "flightNumber")%>
</ItemTemplate>
<EditItemTemplate>
<telerik:GridBoundColumn HeaderText="AirlineCode" UniqueName="AirlineCode" DataField="airlineCode" />
<telerik:GridBoundColumn HeaderText="FlightNumber " EditFormColumnIndex="1" DataField="flightNumber" />
</EditItemTemplate>
</telerik:GridTemplateColumn> ...
...
... more code, but unrelevant to the question here.
</Columns>
But its not working.
Those 2 lines inside are giving warnings:
Element 'GridBoundColumn' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.
Probably I am doing it wrong. Need help.
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
drpcken 是正确的。使用 GridTemplateColumn 时,不需要使用 GridBoundColumn。相反,您可以提供“查看”和“编辑”模板 HTML,并使用
Bind
表达式在“编辑”模板中执行双向绑定。例如:如您所见,您在 ItemTemplate 中使用
Eval
,在 EditItemTemplate 中使用Bind
。所有其他代码应继续工作而无需更改。我还要强调一下 Telerik 论坛。对于 Telerik 的具体问题,有一个活跃的社区可以帮助解决问题:www.telerik.com/forums
drpcken is correct. When you use the GridTemplateColumn, you do not need to use the GridBoundColumn. Instead, you supply the View and Edit template HTML and use the
Bind
expression to do two-way binding in the Edit template. For example:As you can see, you use
Eval
in the ItemTemplate andBind
in the EditItemTemplate. All other code should continue to work without change.Let me also highlight the Telerik Forums. For Telerik specific questions, there is an active community available to help troubleshoot: www.telerik.com/forums
自从我使用 radgrid 以来已经有一段时间了,但在您的编辑模板中,我相信您需要删除 GridBoundColumns 并放置两个由破折号分隔的文本框控件。然后使用 Databinder 填充这些 txt 框。抱歉,我无法更简洁,因为我正在 iPhone 上打字,无法进行测试。当我在我的机器前时,我会跟进你。
祝你好运!
It has been a while since I used the radgrid, but in your edit template I believe you need to remove the GridBoundColumns and put two textbox controls separated by the dash. Then use your Databinder to fill those txt boxes. Sorry I can't be more concise as I'm typing on my iPhone and can't test. I will followup with you when I am in front of my machine.
Good luck!