如何使用 linq to sql 将 Telerik GridBoundColumn 绑定到 sql server 2008 xml 列节点
我使用 linq-to-sql 绑定 radgrid,我使用它绑定网格(因为我将执行 CRUD):
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) {
RadGrid1.DataSource = DbContext.SucursalClienteProveedores;
}
在我的数据库上,我有一个名为 Contact 的列,它是一个 Xml 数据类型,看起来像这样:
<contacto>
<nombre>Andrés Gutiérrez Hernández</nombre>
<cargo>CEO</cargo>
<telefono1>53-93-75-74</telefono1>
<telefono2>044-55-39-40-96-59</telefono2>
<email>[email protected]</email>
</contacto>
行如下所示:
FIN020938SVR |123 |FEAR3434 |Holly Molly| |43 |Andrés Gutiérrez HernándezCEO53-93-75-74044-55-39-40-96-59gutierrez.andres@comprobantes.mx|0 |02/08/2011 12:00:00 am
我正在尝试绑定 GridBoundColumn对于节点 telefono1,在设计器上我做了以下操作:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"
CellSpacing="0" GridLines="None" ondeletecommand="RadGrid1_DeleteCommand"
oninsertcommand="RadGrid1_InsertCommand" onitemcreated="RadGrid1_ItemCreated"
onneeddatasource="RadGrid1_NeedDataSource"
onupdatecommand="RadGrid1_UpdateCommand">
<MasterTableView DataKeyNames="RFC,IDSucursal" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage">
Columns>
<telerik:GridBoundColumn HeaderText="RFC" UniqueName="RFC" DataField="RFCCP">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Alias" UniqueName="Alias" DataField="NombreComercial">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Razon Social" UniqueName="razon_social" DataField="RazonSocial">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="TEL" UniqueName="Tel" DataField="Contacto.telefono1" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Email" UniqueName="Email" >
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
当然TEL 列没有检索任何值,我可以创建一个 linq 查询并返回 IEnumerable 接口,但我想知道是否有一个简单的方法,
提前致谢
I'm binding a radgrid using linq-to-sql, I'm binding the gird using this (cause I'll perform CRUD):
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) {
RadGrid1.DataSource = DbContext.SucursalClienteProveedores;
}
On my DB, I got a column named Contact, it is an Xml datatype and looks like this:
<contacto>
<nombre>Andrés Gutiérrez Hernández</nombre>
<cargo>CEO</cargo>
<telefono1>53-93-75-74</telefono1>
<telefono2>044-55-39-40-96-59</telefono2>
<email>[email protected]</email>
</contacto>
The rows look like this:
FIN020938SVR |123 |FEAR3434 |Holly Molly| |43 |Andrés Gutiérrez HernándezCEO53-93-75-74044-55-39-40-96-59gutierrez.andres@comprobantes.mx|0 |02/08/2011 12:00:00 a.m.
I'm trying to bind a GridBoundColumn to the node telefono1, on the designer I did the following:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"
CellSpacing="0" GridLines="None" ondeletecommand="RadGrid1_DeleteCommand"
oninsertcommand="RadGrid1_InsertCommand" onitemcreated="RadGrid1_ItemCreated"
onneeddatasource="RadGrid1_NeedDataSource"
onupdatecommand="RadGrid1_UpdateCommand">
<MasterTableView DataKeyNames="RFC,IDSucursal" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage">
Columns>
<telerik:GridBoundColumn HeaderText="RFC" UniqueName="RFC" DataField="RFCCP">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Alias" UniqueName="Alias" DataField="NombreComercial">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Razon Social" UniqueName="razon_social" DataField="RazonSocial">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="TEL" UniqueName="Tel" DataField="Contacto.telefono1" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Email" UniqueName="Email" >
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
Of course the TEL column it's not retrieving any values, I could create a linq query and return a IEnumerable interface, but I was wondering if there's an easy way for this,
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道它是否像普通的 XPATH 导航,但你可以尝试:
I don't know if it's like normal XPATH navigation, but you could try:
我认为你需要在 MasterTableView 上面这样的东西
,而 RadGrid 应该如下
并且在后面的代码中
I think you need something like this above the MasterTableView
And the RadGrid should be as follows
And in the code behind