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

RadUpload in an Ajaxified Grid

1 Answer 234 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Cécil
Top achievements
Rank 2
Cécil asked on 17 Nov 2008, 01:16 PM
Hi

I'd like to use the following sample radupload:
http://demos.telerik.com/aspnet/prometheus/Controls/Examples/Integration/RadUploadInAjaxifiedGrid/DefaultCS.aspx?product=upload

But some errors are occurring in the compilation:

Error    1    Brand server unknown: 'sds:SessionDataSource'.    C:\Inetpub\wwwroot\upvb\Default.aspx    103   
Error    3    Element 'SessionDataSource' is not a known element. This can occur if there is a compilation error in the Web site.    C:\Inetpub\wwwroot\upvb\Default.aspx    103    14    C:\...\upvb\
Error    4    Validation (XHTML 1.0 Transitional): Element 'insertparameters' is not supported.    C:\Inetpub\wwwroot\upvb\Default.aspx    108    14    C:\...\upvb\
Error    5    Element 'Parameter' is not a known element. This can occur if there is a compilation error in the Web site.    C:\Inetpub\wwwroot\upvb\Default.aspx    109    22    C:\...\upvb\
Error    7    Element 'SessionParameter' is not a known element. This can occur if there is a compilation error in the Web site.    C:\Inetpub\wwwroot\upvb\Default.aspx    111    22    C:\...\upvb\
Error    8    Validation (XHTML 1.0 Transitional): Element 'updateparameters' is not supported.    C:\Inetpub\wwwroot\upvb\Default.aspx    113    14    C:\...\upvb\
Error    13    Validation (XHTML 1.0 Transitional): Element 'deleteparameters' is not supported.    C:\Inetpub\wwwroot\upvb\Default.aspx    119    14    C:\...\upvb\



Default.aspx

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
<html xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Test</title>
    
</head>
<body class="BODY">
    <form runat="server" id="mainForm" method="post" style="width: 100%">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        
        <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>
        <asp:HiddenField ID="ComboValue" runat="server" />
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="conditionalPostback">
            <telerik:RadProgressManager ID="RadProgressManager1" runat="server" />
            <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
                AutoGenerateColumns="False" Width="97%" DataSourceID="SqlDataSource1" AllowAutomaticInserts="true"
                AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" OnUpdateCommand="RadGrid1_UpdateCommand"
                OnInsertCommand="RadGrid1_InsertCommand" Skin="Web20" OnItemDataBound="RadGrid1_ItemDataBound"
                ShowStatusBar="True" GridLines="None">
                <PagerStyle Mode="NextPrevAndNumeric" />
                <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ID" DataSourceID="SqlDataSource1">
                    <Columns>
                        <telerik:GridEditCommandColumn>
                        </telerik:GridEditCommandColumn>
                        <telerik:GridTemplateColumn HeaderText="Image Name" UniqueName="ImageName" SortExpression="Name">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
<asp:TextBox runat="server" Style="width: 205px; margin-left: 3px;" ID="txbName"
Text='<%# Bind("Name") %>' />
<asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbName"
ErrorMessage="Please, enter a name!" Display="Dynamic" SetFocusOnError="true">
                                </asp:RequiredFieldValidator>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Description" UniqueName="Description" DataField="Description">
                            <ItemTemplate>
                                <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
<asp:TextBox ID="txbDescription" Style="width: 205px; margin-left: 4px;" runat="server"
TextMode="MultiLine" Text='<%# Bind("Description") %>' />
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Image" UniqueName="Upload">
                            <ItemTemplate>
                                <a href="ShowImageCS.aspx?id=<%# Eval("ID") %>">
<asp:Image runat="server" ID="ImageThumbnail" AlternateText="Click here to open the real size image"
ImageUrl='<%# "ShowImageCS.aspx?thumbnail=true&ID=" + Eval("ID")%>' Style="border-width: 0px;" />
                                </a>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadUpload ID="RadUpload1" runat="server" InitialFileInputsCount="1" MaxFileInputsCount="1"
                                    ControlObjectsVisibility="None" MaxFileSize="1000000" AllowedFileExtensions=".jpg,.bmp,.gif,.dib,.jpeg,.jpe,.jfif,.png,.tif,.tiff" />
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridButtonColumn HeaderText="Delete" Text="Delete" CommandName="Delete"
                            UniqueName="column">
                        </telerik:GridButtonColumn>
                    </Columns>
                    <EditFormSettings>
                        <EditColumn UniqueName="EditCommandColumn1">
                        </EditColumn>
                    </EditFormSettings>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                </MasterTableView>
                <FilterMenu EnableTheming="True" Skin="Web20">
                    <CollapseAnimation Duration="200" Type="OutQuint" />
                </FilterMenu>
            </telerik:RadGrid>
        </telerik:RadAjaxPanel>
        <sds:SessionDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
            SelectCommand="SELECT * FROM [Images]"
            InsertCommand="INSERT INTO [Images] ([Name], [Description], [Data]) VALUES (@Name, @Description, @Data)"
            UpdateCommand="UPDATE [Images] SET [Name] = @Name, [Description] = @Description, [Data] = @Data WHERE [ID] = @ID"
            DeleteCommand="DELETE FROM [Images] WHERE [ID] = @ID" PrimaryKeyFields="ID" SessionKey="UploadGridCS">
            <InsertParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:SessionParameter SessionField="DataCS" Name="Data" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:SessionParameter SessionField="DataCS" Name="Data" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
        </sds:SessionDataSource>
        
      
    </form>
</body>
</html>

Default.aspx.vb

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.IO

Imports Telerik.Web.UI
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
End Class



Namespace Telerik.Web.Examples.Ajax.Integration.RadUploadInAjaxifiedGrid
    Partial Public Class DefaultVB

        Inherits System.Web.UI.Page
        Dim RadAjaxPanel1 As RadAjaxPanel
        Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
            InitializeUpdateParameter(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload))
        End Sub

        Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
            InitializeUpdateParameter(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload))
        End Sub

        Private Sub InitializeUpdateParameter(ByVal currentUpload As RadUpload)
            If currentUpload.UploadedFiles.Count > 0 Then
                Dim data As Byte() = New Byte(currentUpload.UploadedFiles(0).ContentLength) {}
                currentUpload.UploadedFiles(0).InputStream.Read(data, 0, data.Length)
                Session("DataVB") = data
            End If
        End Sub

        Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)


            If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then

                Dim upload As RadUpload = DirectCast(e.Item.FindControl("RadUpload1"), RadUpload)
                RadAjaxPanel1.ResponseScripts.Add(String.Format("window['UploadId'] = '{0}';", upload.ClientID))
            End If
        End Sub

    End Class
End Namespace







1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 17 Nov 2008, 03:45 PM
Hello Cécil,

SessionDataSource is a sample control which is used in our online demos. It's purpose is to avoid saving any data to the database. Data is saved in session instead. In real-life scenarios you would use other means of binding RadGrid - SqlDataSource, LinqDataSource or anything else.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Upload (Obsolete)
Asked by
Cécil
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Share this question
or