Telerik RadGrid + RadAjaxManager

时间:2011-08-25 07:39:31

标签: asp.net linq-to-sql c#-4.0 telerik radajaxmanager

让我们直接解决问题。

我有两个网格视图,其中一个生成数据源到另一个。两个网格视图都能够编辑项目(行),但编辑仅适用于第一个网格视图(为另一个网格视图生成数据的网格视图),当我在第二个网格视图中单击编辑时没有任何反应。我已经在网上搜索了一段时间(我相信)发现我需要的是AJAX Manager。

我已经从Telerik的网站上查看了几个示例/演示,但我仍然不确定如何在第二个gridview工作中进行编辑。当我点击第二个gridview中的“编辑”按钮时,根本没有任何事情发生。

两个gridviews内部都有编辑表单,gridview的编辑表单类型都是“WebUserControl”。

目前RadAjaxManager如下所示:

    <telerik:RadAjaxManager ID="ramAsseti" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="gvKontakti">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="gvAsseti" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

有人可以帮我解决一些建议。任何帮助将不胜感激。

编辑:同时我添加了一个RadGrid和更新的RadAjaxManager,我得到的是前两个RadGrids工作(通过“工作”我的意思是我可以单击编辑和用户控件显示),但最后一个没有不行。由于某些奇怪的原因,删除函数 在最后一个RadGrid(gvAsseti)中工作。

这是代码(跳过boundfields,因为它们正常工作):

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxManager ID="ramAsseti" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="gvTvrtke">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="gvTvrtke" />
                <telerik:AjaxUpdatedControl ControlID="gvKontakti" />
                <telerik:AjaxUpdatedControl ControlID="gvAsseti" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="gvTvrtke" runat="server" AllowPaging="True" AllowSorting="True"
    AutoGenerateColumns="False" CellSpacing="0" GridLines="None" OnNeedDataSource="gvTvrtke_NeedDataSource"
    OnItemCommand="gvTvrtke_ItemCommand">
    <MasterTableView DataKeyNames="idFirma" CommandItemDisplay="TopAndBottom" InsertItemPageIndexAction="ShowItemOnCurrentPage">
        <CommandItemSettings AddNewRecordText="Dodaj novu tvrtku" RefreshText="Osvježi" />
        <Columns>
            <telerik:GridButtonColumn UniqueName="ShowAssetsColumn" ButtonType="LinkButton" DataTextFormatString="Kontakti"
                DataTextField="idTvrtka" CommandName="ShowContacts">
            </telerik:GridButtonColumn>
            <telerik:GridBoundColumn UniqueName="Naziv" DataField="Naziv" HeaderText="Naziv">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="OIB" HeaderText="OIB" DataField="OIB">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Tel1" HeaderText="Telefon 1" DataField="Tel1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Tel2" HeaderText="Telefon 2" DataField="Tel2">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Fax" HeaderText="Fax" DataField="Fax">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Mob1" HeaderText="Mobitel 1" DataField="Mob1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Mob2" HeaderText="Mobitel 2" DataField="Mob2">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Email1" HeaderText="E-mail 1" DataField="Email1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Email2" HeaderText="E-mail 2" DataField="Email2">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Adresa1" HeaderText="Adresa" DataField="Adresa1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Web" HeaderText="Web" DataField="Web">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn UniqueName="Aktivan" HeaderText="Aktivan" DataField="Aktivan">
            </telerik:GridCheckBoxColumn>
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
                ConfirmDialogType="RadWindow" ConfirmText="Brisanje tvrtke!" />
        </Columns>
        <EditFormSettings UserControlName="UserControls/TvrtkaUserControl.ascx" EditFormType="WebUserControl">
            <EditColumn UniqueName="EditCommandColumn1">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>
<telerik:RadGrid ID="gvKontakti" runat="server" AllowPaging="True" AllowSorting="True"
    AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Skin="Default" OnNeedDataSource="gvKontakti_NeedDataSource"
    OnDeleteCommand="gvKontakti_DeleteCommand" OnInsertCommand="gvKontakti_InsertCommand"
    OnPreRender="gvKontakti_PreRender" OnUpdateCommand="gvKontakti_UpdateCommand"
    OnItemCommand="gvKontakti_ItemCommand">
    <MasterTableView DataKeyNames="idKontakt" CommandItemDisplay="TopAndBottom" InsertItemPageIndexAction="ShowItemOnCurrentPage">
        <CommandItemSettings AddNewRecordText="Dodaj novi kontakt" RefreshText="Osvježi" />
        <Columns>
            <telerik:GridButtonColumn UniqueName="ShowAssetsColumn" ButtonType="LinkButton" DataTextFormatString="Asseti"
                DataTextField="idKontakt" CommandName="ShowAssets">
            </telerik:GridButtonColumn>
            <telerik:GridBoundColumn UniqueName="Kontakt" DataField="Naziv" HeaderText="Kontakt">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Funkcija" HeaderText="Funkcija" DataField="Funkcija">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Tel1" HeaderText="Telefon 1" DataField="Tel1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Tel2" HeaderText="Telefon 2" DataField="Tel2">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Mob1" HeaderText="Mobitel 1" DataField="Mob1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Mob2" HeaderText="Mobitel 2" DataField="Mob2">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Email1" HeaderText="E-mail 1" DataField="Email1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Email2" HeaderText="E-mail 2" DataField="Email2">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Fax" HeaderText="Fax" DataField="Fax">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn UniqueName="Aktivan" HeaderText="Aktivan" DataField="Aktivan">
            </telerik:GridCheckBoxColumn>
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
                ConfirmDialogType="RadWindow" ConfirmText="Brisanje kontakta!" />
        </Columns>
        <EditFormSettings UserControlName="UserControls/KontaktUserControl.ascx" EditFormType="WebUserControl">
            <EditColumn UniqueName="EditCommandColumn1">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>
<telerik:RadGrid ID="gvAsseti" runat="server" OnNeedDataSource="gvAsseti_NeedDataSource"
    AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellSpacing="0"
    GridLines="None" ondeletecommand="gvAsseti_DeleteCommand" 
    oninsertcommand="gvAsseti_InsertCommand" 
    onupdatecommand="gvAsseti_UpdateCommand">
    <MasterTableView DataKeyNames="idAsset" CommandItemDisplay="TopAndBottom" InsertItemPageIndexAction="ShowItemOnCurrentPage">
        <CommandItemSettings AddNewRecordText="Dodaj novi asset" RefreshText="Prikaži sve assete" />
        <Columns>
            <telerik:GridBoundColumn UniqueName="Naziv" DataField="Naziv" HeaderText="Naziv">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Kod1" HeaderText="Kod 1" DataField="Kod1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Kod2" HeaderText="Kod 2" DataField="Kod">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="DatumGarancije" HeaderText="Datum garancije"
                DataField="DatumGarancije">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn UniqueName="Aktivan" HeaderText="Aktivan" DataField="Aktivan">
            </telerik:GridCheckBoxColumn>
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete"
                ConfirmDialogType="RadWindow" ConfirmText="Brisanje asseta!" />
        </Columns>
        <EditFormSettings UserControlName="UserControls/AssetUserControl.ascx" EditFormType="WebUserControl">
            <EditColumn UniqueName="EditCommandColumn1">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>

1 个答案:

答案 0 :(得分:6)

我想如果您只是将gvAsseti添加到这样的AJAX设置中,它应该可以正常工作:

而不是:

<telerik:RadAjaxManager ID="ramAsseti" runat="server">
   <AjaxSettings>
       <telerik:AjaxSetting AjaxControlID="gvKontakti">
           <UpdatedControls>
               <!-- DON'T PUT THEM HERE -->
           </UpdatedControls>
       </telerik:AjaxSetting> 
   </AjaxSettings>
</telerik:RadAjaxManager>

执行此操作(注意每个网格的 AjaxSetting ):

<telerik:RadAjaxManager ID="ramAsseti" runat="server">
   <AjaxSettings>
       <telerik:AjaxSetting AjaxControlID="gvKontakti" /> 
       <telerik:AjaxSetting AjaxControlID="gvAsseti" /> 
       <telerik:AjaxSetting AjaxControlID="gvTvrtke" />
   </AjaxSettings>
</telerik:RadAjaxManager>

另一种方法是使用RadAjaxPanel,并将所有网格放在其中。这将确保一切都是AJAX:

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">

   <telerik:RadGrid ... >

   <telerik:Radgrid ... >

   <telerik:RadGrid ... >

</telerik:RadAjaxPanel>