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

radUpload issues in radGrid using Ajax

2 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aamir
Top achievements
Rank 1
Aamir asked on 09 Nov 2012, 05:50 PM
I am having issues when I use radUpload in the radGrid, I can't insert new records when I use radUpload.

I am using radTabs and Multipage and .ascx files. My radGrid is on user control file.
My code is below

<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
 
        <script type="text/javascript">
            var uploadId;
            var AuthorImagesListId;
            //on insert and update buttons click temporarily disables ajax to perform upload actions
            function conditionalPostback(sender, e) {
                var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
                if (e.EventTarget.match(theRegexp)) {
                    var upload = $find(uploadId);
 
                    //AJAX is disabled only if file is selected for upload
                    if (upload.getFileInputs()[0].value != "") {
                        e.set_enableAjax(false);
                    }
                }
            }
 
        </script>
 
    </telerik:RadCodeBlock
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="RadWindowManager1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>        
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
 
 <telerik:radprogressmanager id="RadProgressManager1" runat="server" />
 
             
         
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True"
    AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True"
    AutoGenerateColumns="False" DataSourceID="SqlDataSource1" GridLines="None"
    ShowStatusBar="True" Skin="Hay" AllowSorting="True">
 
    <PagerStyle Mode="NextPrevAndNumeric" />
    <GroupingSettings CaseSensitive="False"></GroupingSettings>
     <%--DOUBLE CLICKING ON GRIDVIEW ROW ACTIVATES THE EDIT ROW MODE--%>          
    <ClientSettings>
                <ClientEvents OnRowDblClick="RowDblClick" />
    </ClientSettings>
    <GroupingSettings CaseSensitive="False" />
    <ClientSettings AllowRowsDragDrop="True">
<ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
    </ClientSettings>
 
 
<MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="nauhaID" DataSourceID="SqlDataSource1" HorizontalAlign="NotSet" AutoGenerateColumns="false" >
    <Columns>
 
        <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderText="Edit "
            UniqueName="EditCommandColumn1">
            <ItemStyle CssClass="MyImageButton" />
        </telerik:GridEditCommandColumn>
 
        <telerik:GridBoundColumn DataField="title"
            HeaderText="Nauha Title" SortExpression="title" ColumnEditorID="GridTxtboxTemp"
            UniqueName="title">
        </telerik:GridBoundColumn>
 
         
        <telerik:GridDropDownColumn DataField="areaID" DataSourceID="SqlDataSource2"
            HeaderText="Area Name" ListTextField="areaName" ListValueField="areaID"
            UniqueName="column1" ColumnEditorID="GridDropDownColumnEditor1">
        </telerik:GridDropDownColumn>
 
        <telerik:GridBoundColumn DataField="author" HeaderText="author" ColumnEditorID="GridTxtboxTemp" Visible="false"
            SortExpression="author" UniqueName="author">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="lyrics" HeaderText="lyrics" Visible="false"
            SortExpression="lyrics" UniqueName="lyrics">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="reciter" HeaderText="reciter" ColumnEditorID="GridTxtboxTemp"  Visible="false"
            SortExpression="reciter" UniqueName="reciter">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="year" DataType="System.Int16"
            HeaderText="year" SortExpression="year" UniqueName="year">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="format" HeaderText="format"
            SortExpression="format" UniqueName="format">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="duration" DataType="System.TimeSpan" 
            HeaderText="duration" SortExpression="duration" UniqueName="duration">
        </telerik:GridBoundColumn>
 
        <telerik:GridBoundColumn DataField="size" HeaderText="size"
            SortExpression="size" UniqueName="size">
        </telerik:GridBoundColumn>
 
        <telerik:GridBoundColumn DataField="tags" HeaderText="tags" SortExpression="tags" Visible="false"
            UniqueName="tags">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="counter" DataType="System.Int32"
            HeaderText="counter" SortExpression="counter" UniqueName="counter">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="uploader" HeaderText="uploader"
            SortExpression="uploader" UniqueName="uploader">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="date" HeaderText="date" DataFormatString="{0:d}" 
            SortExpression="date" UniqueName="date" DataType="System.DateTime">
        </telerik:GridBoundColumn>
        <telerik:GridCheckBoxColumn DataField="Discontinued" DataType="System.Boolean"
            HeaderText="Discontinued" SortExpression="Discontinued"
            UniqueName="Discontinued" EditFormColumnIndex="1">
        </telerik:GridCheckBoxColumn>
 
         
        <%--TEMPLATE COLUMN FOR UPLOADING--%>
        <telerik:GridTemplateColumn DataField="url" HeaderText="URL New"
            SortExpression="url" UniqueName="urlUpload">
            <EditItemTemplate>
                <telerik:RadUpload ID="RadUpload1" Runat="server" InitialFileInputsCount="1" MaxFileInputsCount="1" maxfilesize="1000000"
                    ControlObjectsVisibility="None" >
                </telerik:RadUpload>
            </EditItemTemplate>
 
            <ItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server"
                    NavigateUrl='<%# Eval("url") %>'
                    Text='<%# Eval("title") %>'></asp:HyperLink>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
 
        
       
         
        <telerik:GridButtonColumn ConfirmText=" Are you sure you want to Delete this Nauha?" ConfirmDialogType="RadWindow"
                        ConfirmTitle="Delete" ButtonType="ImageButton"
            CommandName="Delete" Text="Delete"
                        UniqueName="DeleteColumn" HeaderText="Delete">
        </telerik:GridButtonColumn>
 
       
 
 
    </Columns>
     <%--RECORD EDIT/INSERT OPTIONS--%>
<EditFormSettings>
     
 
 
    <EditColumn UniqueName="EditCommandColumn1"></EditColumn>
    <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"
                        UniqueName="EditCommandColumn1" CancelText="Cancel edit">
    </EditColumn>
</EditFormSettings>
</MasterTableView>
   <%--DOUBLE CLICKING ON GRIDVIEW ROW ACTIVATES THE EDIT ROW MODE--%>          
    <ClientSettings>
                <ClientEvents OnRowDblClick="RowDblClick" />
    </ClientSettings>
</telerik:RadGrid>
<telerik:GridTextBoxColumnEditor ID="GridTxtboxTemp" runat="server" TextBoxStyle-Width="300px" />
<telerik:GridDropDownListColumnEditor ID="GridDropDownColumnEditor1" runat="server" DropDownStyle-Width="200px" />
 
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
    ConnectionString="<%$ ConnectionStrings:muharramConnectionString %>"
    SelectCommand="SELECT * FROM [AreaName]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConflictDetection="CompareAllValues"
    ConnectionString="<%$ ConnectionStrings:muharramConnectionString %>"
    DeleteCommand="DELETE FROM [Nauha] WHERE [nauhaID] = @original_nauhaID AND [title] = @original_title AND (([author] = @original_author) OR ([author] IS NULL AND @original_author IS NULL)) AND (([lyrics] = @original_lyrics) OR ([lyrics] IS NULL AND @original_lyrics IS NULL)) AND (([reciter] = @original_reciter) OR ([reciter] IS NULL AND @original_reciter IS NULL)) AND (([year] = @original_year) OR ([year] IS NULL AND @original_year IS NULL)) AND (([format] = @original_format) OR ([format] IS NULL AND @original_format IS NULL)) AND (([duration] = @original_duration) OR ([duration] IS NULL AND @original_duration IS NULL)) AND (([size] = @original_size) OR ([size] IS NULL AND @original_size IS NULL)) AND (([url] = @original_url) OR ([url] IS NULL AND @original_url IS NULL)) AND (([tags] = @original_tags) OR ([tags] IS NULL AND @original_tags IS NULL)) AND (([counter] = @original_counter) OR ([counter] IS NULL AND @original_counter IS NULL)) AND (([uploader] = @original_uploader) OR ([uploader] IS NULL AND @original_uploader IS NULL)) AND (([date] = @original_date) OR ([date] IS NULL AND @original_date IS NULL)) AND (([areaID] = @original_areaID) OR ([areaID] IS NULL AND @original_areaID IS NULL)) AND (([Discontinued] = @original_Discontinued) OR ([Discontinued] IS NULL AND @original_Discontinued IS NULL))"
    InsertCommand="INSERT INTO [Nauha] ([title], [author], [lyrics], [reciter], [year], [format], [duration], [size], [url], [tags], [counter], [uploader], [date], [areaID], [Discontinued]) VALUES (@title, @author, @lyrics, @reciter, @year, @format, @duration, @size, @url, @tags, @counter, @uploader, @date, @areaID, @Discontinued)"
    OldValuesParameterFormatString="original_{0}"
    SelectCommand="SELECT * FROM [Nauha] ORDER BY [areaID]"
     
    UpdateCommand="UPDATE [Nauha] SET [title] = @title, [author] = @author, [lyrics] = @lyrics, [reciter] = @reciter, [year] = @year, [format] = @format, [duration] = @duration, [size] = @size, [url] = @url, [tags] = @tags, [counter] = @counter, [uploader] = @uploader, [date] = @date, [areaID] = @areaID, [Discontinued] = @Discontinued WHERE [nauhaID] = @original_nauhaID AND [title] = @original_title AND (([author] = @original_author) OR ([author] IS NULL AND @original_author IS NULL)) AND (([lyrics] = @original_lyrics) OR ([lyrics] IS NULL AND @original_lyrics IS NULL)) AND (([reciter] = @original_reciter) OR ([reciter] IS NULL AND @original_reciter IS NULL)) AND (([year] = @original_year) OR ([year] IS NULL AND @original_year IS NULL)) AND (([format] = @original_format) OR ([format] IS NULL AND @original_format IS NULL)) AND (([duration] = @original_duration) OR ([duration] IS NULL AND @original_duration IS NULL)) AND (([size] = @original_size) OR ([size] IS NULL AND @original_size IS NULL)) AND (([url] = @original_url) OR ([url] IS NULL AND @original_url IS NULL)) AND (([tags] = @original_tags) OR ([tags] IS NULL AND @original_tags IS NULL)) AND (([counter] = @original_counter) OR ([counter] IS NULL AND @original_counter IS NULL)) AND (([uploader] = @original_uploader) OR ([uploader] IS NULL AND @original_uploader IS NULL)) AND (([date] = @original_date) OR ([date] IS NULL AND @original_date IS NULL)) AND (([areaID] = @original_areaID) OR ([areaID] IS NULL AND @original_areaID IS NULL)) AND (([Discontinued] = @original_Discontinued) OR ([Discontinued] IS NULL AND @original_Discontinued IS NULL))">
    <DeleteParameters>
        <asp:Parameter Name="original_nauhaID" Type="Int32" />
        <asp:Parameter Name="original_title" Type="String" />
        <asp:Parameter Name="original_author" Type="String" />
        <asp:Parameter Name="original_lyrics" Type="String" />
        <asp:Parameter Name="original_reciter" Type="String" />
        <asp:Parameter Name="original_year" Type="Int16" />
        <asp:Parameter Name="original_format" Type="String" />
        <asp:Parameter DbType="Time" Name="original_duration" />
        <asp:Parameter Name="original_size" Type="String" />
        <asp:Parameter Name="original_url" Type="String" />
        <asp:Parameter Name="original_tags" Type="String" />
        <asp:Parameter Name="original_counter" Type="Int32" />
        <asp:Parameter Name="original_uploader" Type="String" />
        <asp:Parameter Name="original_date" Type="DateTime" />
        <asp:Parameter Name="original_areaID" Type="Int32" />
        <asp:Parameter Name="original_Discontinued" Type="Boolean" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="title" Type="String" />
        <asp:Parameter Name="author" Type="String" />
        <asp:Parameter Name="lyrics" Type="String" />
        <asp:Parameter Name="reciter" Type="String" />
        <asp:Parameter Name="year" Type="Int16" />
        <asp:Parameter Name="format" Type="String" />
        <asp:Parameter DbType="Time" Name="duration" />
        <asp:Parameter Name="size" Type="String" />
        <asp:Parameter Name="url" Type="String" />
        <asp:Parameter Name="tags" Type="String" />
        <asp:Parameter Name="counter" Type="Int32" />
        <asp:Parameter Name="uploader" Type="String" />
        <asp:Parameter Name="date" Type="DateTime" />
        <asp:Parameter Name="areaID" Type="Int32" />
        <asp:Parameter Name="Discontinued" Type="Boolean" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="title" Type="String" />
        <asp:Parameter Name="author" Type="String" />
        <asp:Parameter Name="lyrics" Type="String" />
        <asp:Parameter Name="reciter" Type="String" />
        <asp:Parameter Name="year" Type="Int16" />
        <asp:Parameter Name="format" Type="String" />
        <asp:Parameter DbType="Time" Name="duration" />
        <asp:Parameter Name="size" Type="String" />
        <asp:Parameter Name="url" Type="String" />
        <asp:Parameter Name="tags" Type="String" />
        <asp:Parameter Name="counter" Type="Int32" />
        <asp:Parameter Name="uploader" Type="String" />
        <asp:Parameter Name="date" Type="DateTime" />
        <asp:Parameter Name="areaID" Type="Int32" />
        <asp:Parameter Name="Discontinued" Type="Boolean" />
        <asp:Parameter Name="original_nauhaID" Type="Int32" />
        <asp:Parameter Name="original_title" Type="String" />
        <asp:Parameter Name="original_author" Type="String" />
        <asp:Parameter Name="original_lyrics" Type="String" />
        <asp:Parameter Name="original_reciter" Type="String" />
        <asp:Parameter Name="original_year" Type="Int16" />
        <asp:Parameter Name="original_format" Type="String" />
        <asp:Parameter DbType="Time" Name="original_duration" />
        <asp:Parameter Name="original_size" Type="String" />
        <asp:Parameter Name="original_url" Type="String" />
        <asp:Parameter Name="original_tags" Type="String" />
        <asp:Parameter Name="original_counter" Type="Int32" />
        <asp:Parameter Name="original_uploader" Type="String" />
        <asp:Parameter Name="original_date" Type="DateTime" />
        <asp:Parameter Name="original_areaID" Type="Int32" />
        <asp:Parameter Name="original_Discontinued" Type="Boolean" />
    </UpdateParameters>
</asp:SqlDataSource>

Code Behind

Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
         
        If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
            Dim upload As RadUpload = e.Item.FindControl("RadUpload1")
            Dim script As String = String.Format("uploadId = '{0}';", upload.ClientID)
            ScriptManager.RegisterStartupScript(Page, Page.[GetType](), "initialize", script, True)
        End If
End Sub
 
 
 Protected Sub RadGrid1_ItemInserted(source As Object, e As Telerik.Web.UI.GridInsertedEventArgs) Handles RadGrid1.ItemInserted
        Dim item As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
        Dim uploader As RadUpload = TryCast(e.Item.FindControl("RadUpload1"), RadUpload)
        Dim myUploadedFile As UploadedFile = uploader.UploadedFiles(0)
        Dim fileName As String = myUploadedFile.FileName
 
        'Gets the uploaded file extension
        Dim fileExt As String
        fileExt = System.IO.Path.GetExtension(myUploadedFile.FileName).ToLower
 
        myUploadedFile.SaveAs("~/Uploads/" & fileName)
         
    End Sub

2 Answers, 1 is accepted

Sort by
0
Aamir
Top achievements
Rank 1
answered on 10 Nov 2012, 08:50 PM
Somebody please provide help
0
Radoslav
Telerik team
answered on 14 Nov 2012, 07:24 AM
Hi Aamir,

To achieve the desired functionality you could try handling the InsertCommand of the RadGrid and extract the uploaded file from the RadUpload control. The same approach is used into the code library and the following example:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandradasyncupload/defaultcs.aspx?product=grid
Also in your case you could pass the value to the "url" insert parameter of the SqlDataSource into the InsertCommand. More information about passing parameters to the SqlDataSource you could find here:
http://forums.asp.net/t/1115044.aspx/1
http://www.dreamincode.net/forums/topic/187000-parameter-for-sqldatasource-inserting-using-c%23/
http://stackoverflow.com/questions/988614/how-can-i-set-the-sqldatasource-parameters-value

I hope this helps.

Greetings,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Aamir
Top achievements
Rank 1
Answers by
Aamir
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or