如何使用 linq to sql 将 Telerik GridBoundColumn 绑定到 sql server 2008 xml 列节点

发布于 2024-11-28 07:30:36 字数 2419 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑忘罢 2024-12-05 07:30:36

我不知道它是否像普通的 XPATH 导航,但你可以尝试:

DataField="Contacto/telefono1"

I don't know if it's like normal XPATH navigation, but you could try:

DataField="Contacto/telefono1"
演出会有结束 2024-12-05 07:30:36

我认为你需要在 MasterTableView 上面这样的东西

    <telerik:RadAjaxManagerProxy runat="server" ID="RadAjaxManagerProxy1">
          <AjaxSettings>
         <telerik:AjaxSetting AjaxControlID="btnAddCustomer">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadAjaxPanel1" />
            </UpdatedControls>
          </AjaxSettings>
   </telerik:RadAjaxManagerProxy>

,而 RadGrid 应该如下

    <telerik:RadGrid ID="rgLeads" runat="server" Skin="Vista" Width="100%" AllowPaging="true" PageSize="5" AllowCustomPaging="true">

并且在后面的代码中

    rgLeads.VirtualItemCount = 'stored proc here
    rgLeads.Rebind()

I think you need something like this above the MasterTableView

    <telerik:RadAjaxManagerProxy runat="server" ID="RadAjaxManagerProxy1">
          <AjaxSettings>
         <telerik:AjaxSetting AjaxControlID="btnAddCustomer">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadAjaxPanel1" />
            </UpdatedControls>
          </AjaxSettings>
   </telerik:RadAjaxManagerProxy>

And the RadGrid should be as follows

    <telerik:RadGrid ID="rgLeads" runat="server" Skin="Vista" Width="100%" AllowPaging="true" PageSize="5" AllowCustomPaging="true">

And in the code behind

    rgLeads.VirtualItemCount = 'stored proc here
    rgLeads.Rebind()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文