This is a migrated thread and some comments may be shown as answers.

Problem with RadUpload inside RadGrid

4 Answers 155 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 31 Aug 2008, 06:02 PM

here is my aspx code

Page Language="VB" MasterPageFile="~/internal1.master" AutoEventWireup="false" CodeFile="objectType.aspx.vb" Inherits="internal_parameter_catalog_objectType" title="Untitled Page" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <telerik:radscriptblock id="RadScriptBlock1" runat="server">
                <script type="text/javascript">
                    //On insert and update buttons click temporarily disables ajax to perform upload actions
                    function conditionalPostback(e, sender)
                    {
                        var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
                  if (sender.EventTarget.match(theRegexp))
                  {
                      var upload = $find(window['UploadId']);
                     
                      //AJAX is disabled only if file is selected for upload
                      if(upload.getFileInputs()[0].value != "")
                      {
                          sender.EnableAjax = false;
                      }
                  }
                    }    
                </script>
            </telerik:radscriptblock>
           
           
    <span style="font-size: 16pt; font-family: 新細明體"><strong><em>館藏類型編輯作業</em></strong></span>
        <br /><br />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" Style="position: static">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px"
        Style="position: static" Transparency="50" Width="75px">
        <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>'
            style="border: 0px;" />
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"
        clientevents-onrequeststart="conditionalPostback">
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
        AllowAutomaticUpdates="True" AllowMultiRowEdit="True" AllowMultiRowSelection="True"
        AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
        GridLines="None" PageSize="25" ShowStatusBar="True" Skin="Office2007" Style="position: static">
        <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="TopAndBottom" />
        <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="itemtype" DataSourceID="SqlDataSource1" GridLines="None" NoDetailRecordsText="系統裡沒有子資料" NoMasterRecordsText="系統裡沒有資料">
            <RowIndicatorColumn>
                <HeaderStyle Width="20px" />
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px" />
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
                    <HeaderTemplate>
                        <asp:CheckBox ID="headerChkbox" runat="server" AutoPostBack="True" OnCheckedChanged="ToggleSelectedState"
                            Style="position: static" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="ToggleRowSelection"
                            Style="position: static" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="itemtype" HeaderText="類型代碼" ReadOnly="True" SortExpression="itemtype"
                    UniqueName="itemtype">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="description" HeaderText="館藏類型" SortExpression="description"
                    UniqueName="description">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="createdate" DataType="System.DateTime" HeaderText="建檔日期"
                    SortExpression="createdate" UniqueName="createdate">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="createname" HeaderText="建檔人" SortExpression="createname"
                    UniqueName="createname">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="storeno" HeaderText="所屬館藏" SortExpression="storeno"
                    UniqueName="storeno">
                </telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelText="放棄" EditText="修改" InsertText="儲存新增" UpdateText="儲存修改">
                </telerik:GridEditCommandColumn>
                <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="删除"
                    UniqueName="column" ConfirmText="資料將被删除,請確認!" ConfirmTitle="資料删除確認">
                </telerik:GridButtonColumn>
            </Columns>
            <CommandItemTemplate>
                <asp:LinkButton ID="btnEditSelected" runat="server" CausesValidation="false" CommandName="EditSelected"
                    Style="vertical-align: bottom; position: static" Visible="<%# RadGrid1.EditIndexes.Count = 0 %>"><img style="border:0px;vertical-align:middle;" alt="" src="../../../pics/action/Edit.gif" /> 修改選取資料</asp:LinkButton><asp:LinkButton
                        ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Style="position: static"
                        Visible="<%# RadGrid1.EditIndexes.Count > 0 %>"><img style="border:0px;vertical-align:middle;" alt="" src="../../../pics/action/Update.gif" /> 儲存修改資料</asp:LinkButton><asp:LinkButton
                            ID="btnCancel" runat="server" CausesValidation="false" CommandName="CancelAll"
                            Style="position: static" Visible="<%# RadGrid1.EditIndexes.Count > 0 Or RadGrid1.MasterTableView.IsItemInserted %>"><img style="border:0px;vertical-align:middle;" alt="" src="../../../pics/action/Cancel.gif" /> 放棄編輯</asp:LinkButton><asp:LinkButton
                                ID="LinkButton2" runat="server" CommandName="InitInsert" Style="position: static"
                                Visible="<%# Not RadGrid1.MasterTableView.IsItemInserted %>"><img style="border:0px;vertical-align:middle;" alt="" src="../../../pics/action/AddRecord.gif" /> 新增資料</asp:LinkButton><asp:LinkButton
                                    ID="LinkButton3" runat="server" CommandName="PerformInsert" Style="position: static"
                                    Visible="<%# RadGrid1.MasterTableView.IsItemInserted %>"><img style="border:0px;vertical-align:middle;" alt="" src="../../../pics/action/Insert.gif" /> 儲存新增資料</asp:LinkButton><asp:LinkButton
                                        ID="LinkButton1" runat="server" CausesValidation="false" CommandName="DeleteSelected"
                                        OnClientClick="javascript:return confirm('Delete all selected Products?')" Style="position: static"><img style="border:0px;vertical-align:middle;" alt="" src="../../../pics/action/Delete.gif" /> 刪除選取資料</asp:LinkButton>
                <asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid" Style="position: static"><img style="border:0px;vertical-align:middle;" alt="" src="../../../pics/action/Refresh.gif" /> 重新整理</asp:LinkButton>
            </CommandItemTemplate>
            <EditFormSettings EditFormType="Template">
                <EditColumn UniqueName="EditCommandColumn1">
                </EditColumn>
                <FormTemplate>
                    <table style="position: static" width="100%">
                        <tr>
                            <td>
                                <table style="position: static">
                                    <tr>
                                        <td>
                                            <span style="color: #ff0000">*</span>類型代碼:</td>
                                        <td>
                                            <telerik:RadTextBox ID="RadTextBox1" runat="server" Style="position: static" Text='<%# Bind("itemtype") %>'
                                                Width="125px">
                                            </telerik:RadTextBox></td>
                                        <td>
                                            <span style="color: #ff0000">*</span>館藏類型:</td>
                                        <td>
                                            <telerik:RadTextBox ID="RadTextBox2" runat="server" Style="position: static" Text='<%# Bind("description") %>'
                                                Width="250px">
                                            </telerik:RadTextBox></td>
                                    </tr>
                                </table>
                                <table style="position: static">
                                    <tr>
                                        <td style="width: 100px">
                                            <span style="color: #ff0000">*</span>館藏類型圖示:</td>
                                    </tr>
                                </table>
                                &nbsp;
                                <table style="position: static">
                                    <tr>
                                        <td>
                                           
                                            <asp:RadioButtonList ID="RadioButtonList1" runat="server" Style="position: static">
                                                <asp:ListItem Selected="True"> </asp:ListItem>
                                                <asp:ListItem> </asp:ListItem>
                                                <asp:ListItem> </asp:ListItem>
                                            </asp:RadioButtonList></td>
                                        <td>
                                            <telerik:RadComboBox ID="RadComboBox1" runat="server"
                                                Skin="Office2007" Style="position: static" DataSourceID="SqlDataSourceimage1" DataTextField="name" DataValueField="url2" Width="250px">
                                                <CollapseAnimation Duration="200" Type="OutQuint" />
                                                <ItemTemplate>
                                                    <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("url2") %>' Style="position: static" />
                                                    <asp:Label ID="Label1" runat="server" Style="position: static" Text='<%# Eval("name") %>'></asp:Label>
                                                </ItemTemplate>
                                            </telerik:RadComboBox>
                                            <br />
                                            <br />
                                            <asp:Label ID="Label2" runat="server" Style="position: static" Text="沒有代表圖示"></asp:Label><br />
                                            <br />
                                            <asp:Label ID="Label3" runat="server" Style="position: static" Text="自定代表圖示"></asp:Label></td>
                                    </tr>
                                    <tr>
                                        <td>
                                        </td>
                                        <td>
                                            <telerik:RadUpload ID="RadUpload1" runat="server" AllowedFileExtensions=".jpg,.bmp,.gif,.dib,.jpeg,.jpe,.jfif,.png,.tif,.tiff"
                                                ControlObjectsVisibility="None" MaxFileInputsCount="1"
                                                MaxFileSize="1000000" Skin="Vista" Style="position: static" TargetFolder="~/store/UserItemImage">
                                            </telerik:RadUpload>
                                        </td>
                                    </tr>
                                </table>
                                <table style="position: static">
                                    <tr>
                                        <td>
                                            備註:</td>
                                        <td>
                                            <telerik:RadTextBox ID="RadTextBox3" runat="server" Height="50px" Style="position: static"
                                                Text='<%# Bind("summary") %>' TextMode="MultiLine" Width="250px">
                                            </telerik:RadTextBox></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <asp:Button ID="btnUpdate" runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update") %>'
                                    Style="position: static" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "儲存新增", "儲存修改") %>' /><asp:Button
                                        ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel" Style="position: static"
                                        Text="放棄編輯" /></td>
                        </tr>
                    </table>
                    <asp:HiddenField ID="createdateHiddenField" runat="server" Value='<%# Bind("createdate") %>' />
                    <asp:HiddenField ID="createnameHiddenField" runat="server" Value='<%# Bind("createname") %>' />
                    <asp:HiddenField ID="storenoHiddenField" runat="server" Value='<%# Bind("storeno") %>' /><asp:HiddenField ID="imageurlHiddenField" runat="server" Value='<%# Bind("imageurl") %>' />
                    <asp:HiddenField ID="imagenameHiddenField" runat="server" Value='<%# Bind("imagename") %>' />
                </FormTemplate>
            </EditFormSettings>
            <PagerStyle Mode="NextPrevNumericAndAdvanced" PagerTextFormat="轉換頁面: {4} &amp;nbsp;現顯示頁面 {0} of {1}, 資料數量 {2} to {3} of {5}."
                Position="TopAndBottom" />
        </MasterTableView>
        <ClientSettings AllowKeyboardNavigation="True" EnableRowHoverStyle="True">
        </ClientSettings>
        <FilterMenu EnableTheming="True" Skin="Sunset">
            <CollapseAnimation Duration="200" Type="OutQuint" />
        </FilterMenu>
    </telerik:RadGrid></telerik:RadAjaxPanel>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LIB1.0ConnectionString %>"
        DeleteCommand="DELETE FROM [parameter_catalog_objectType] WHERE [itemtype] = @itemtype"
        InsertCommand="INSERT INTO [parameter_catalog_objectType] ([itemtype], [description], [imageurl], [imagename], [summary], [createdate], [createname], [storeno]) VALUES (@itemtype, @description, @imageurl, @imagename, @summary, @createdate, @createname, @storeno)"
        SelectCommand="SELECT * FROM [parameter_catalog_objectType]" UpdateCommand="UPDATE [parameter_catalog_objectType] SET [description] = @description, [imageurl] = @imageurl, [imagename] = @imagename, [summary] = @summary, [createdate] = @createdate, [createname] = @createname, [storeno] = @storeno WHERE [itemtype] = @itemtype">
        <DeleteParameters>
            <asp:Parameter Name="itemtype" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="description" Type="String" />
            <asp:Parameter Name="imageurl" Type="String" />
            <asp:Parameter Name="imagename" Type="String" />
            <asp:Parameter Name="summary" Type="String" />
            <asp:Parameter Name="createdate" Type="DateTime" />
            <asp:Parameter Name="createname" Type="String" />
            <asp:Parameter Name="storeno" Type="String" />
            <asp:Parameter Name="itemtype" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="itemtype" Type="String" />
            <asp:Parameter Name="description" Type="String" />
            <asp:Parameter Name="imageurl" Type="String" />
            <asp:Parameter Name="imagename" Type="String" />
            <asp:Parameter Name="summary" Type="String" />
            <asp:Parameter Name="createdate" Type="DateTime" />
            <asp:Parameter Name="createname" Type="String" />
            <asp:Parameter Name="storeno" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSourceimage1" runat="server" ConnectionString="<%$ ConnectionStrings:LIB1.0ConnectionString %>"
        SelectCommand="SELECT * FROM [catalog_objectTypeImgUrl]"></asp:SqlDataSource>
            
   
</asp:Content>

here is my code behind 

 Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand
        If e.Item.OwnerTableView.DataSourceID = "SqlDataSource1" Then
            If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
                Dim uploader As RadUpload = TryCast(e.Item.FindControl("RadUpload1"), RadUpload)
                Dim imageurl As HiddenField = TryCast(e.Item.FindControl("imageurlHiddenField"), HiddenField)
                Dim imagename As HiddenField = TryCast(e.Item.FindControl("imagenameHiddenField"), HiddenField)
                Dim imageFile As UploadedFile = Nothing
                If uploader.UploadedFiles.Count > 0 Then
                    imageFile = uploader.UploadedFiles(0)
                    imageurl.Value = "~/store/UserItemImage/" & imageFile.FileName
                    imagename.Value = imageFile.FileName

                End If
            End If
        End If

    End Sub

Is anyone can tell me why the Radupload is not uploadable in the Radgrid, I have been following the online demo to put the script below:

<telerik:radscriptblock id="RadScriptBlock1" runat="server">
                <script type="text/javascript">
                    //On insert and update buttons click temporarily disables ajax to perform upload actions
                    function conditionalPostback(e, sender)
                    {
                        var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
                  if (sender.EventTarget.match(theRegexp))
                  {
                      var upload = $find(window['UploadId']);
                     
                      //AJAX is disabled only if file is selected for upload
                      if(upload.getFileInputs()[0].value != "")
                      {
                          sender.EnableAjax = false;
                      }
                  }
                    }    
                </script>
            </telerik:radscriptblock>

to disable ajx. Can anyone give me a help please! I found it the uploader is no upload any thing to my target file at all. Thank you

4 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 02 Sep 2008, 02:16 PM
Hi Paul,

Have you added this in the ItemDataBound event handler?

        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                RadUpload upload = e.Item.FindControl("RadUpload1"as RadUpload; 
                RadAjaxPanel1.ResponseScripts.Add(string.Format("window['UploadId'] = '{0}';", upload.ClientID)); 
            } 
        } 


Best wishes,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Paul
Top achievements
Rank 1
answered on 02 Sep 2008, 03:43 PM
yes I tried you suggestion but still is no upload action heppan. Is it because i turn the edit form into Template, so my insert and edit button id is "btnUpdate" so what should i  do something on it?

<asp:Button ID="btnUpdate" runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update") %>'
                                    Style="position: static" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "儲存新增", "儲存修改") %>' />
0
Veselin Vasilev
Telerik team
answered on 05 Sep 2008, 12:30 PM
Hi Paul,

Please find attached a working sample.

Regards,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dorababu
Top achievements
Rank 1
answered on 13 Aug 2012, 12:14 PM
I tried your code but when I am updating with out selecting any file it is allowing the file to be saved.
Tags
Upload (Obsolete)
Asked by
Paul
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Paul
Top achievements
Rank 1
Dorababu
Top achievements
Rank 1
Share this question
or