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

Automatic operations and upload

2 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Per Holmqvist
Top achievements
Rank 2
Per Holmqvist asked on 24 Feb 2009, 10:45 PM
I have a problem with upload in my grid using Automatic operations
In your example you have the following code
    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 

My problem is that you are sending the data to the Session("DataVB") and not to the grid.
How do i change that if i have automatic inserts with stored procedures like
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"   
                SelectCommandType="StoredProcedure" 
                SelectCommand="Selectimage" 
                DeleteCommandType="StoredProcedure" 
                DeleteCommand="Deleteimage" 
                UpdateCommandType="StoredProcedure" 
                UpdateCommand="Updateimage" 
                InsertCommandType="StoredProcedure" 
                InsertCommand="Insertimage">  
                <UpdateParameters> 
                    <asp:Parameter Name="FileName" Type="String" /> 
                    <asp:Parameter Name="imageID" Type="int32" /> 
                </UpdateParameters> 
                <InsertParameters> 
                    <asp:Parameter Name="FileName" Type="String" /> 
                </InsertParameters> 
            </asp:SqlDataSource> 

I need the uploaded filenmae to hook on the Filename parameter.
Any suggestions how to?


And to make it more compplex, I only want the upload on insert, not on upodate, there it should be a normal textbox.

is this possible at all?

2 Answers, 1 is accepted

Sort by
0
Per Holmqvist
Top achievements
Rank 2
answered on 26 Feb 2009, 10:28 PM
Pushing up, still no reply? :(
0
Georgi Krustev
Telerik team
answered on 04 Mar 2009, 10:12 AM
Hello,

To attain the functionality you are lookin for you need to wire the code to the ItemCommand event. When it is raised you need to check whether an inserting action is performed. If a new item is inserted, you can use InsertItem(IDictionary newValues) method to modify the required values. The new Item of Telerik RadGrid will be bound to an empty object with only values taken from the newValues dictionary.

Here is a code snippet showing how to achieve this:
 Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As  Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand 
    If e.CommandName = RadGrid.InitInsertCommandName Then '"Add new" button clicked 
      e.Canceled = True 
      'Prepare an IDictionary with the predefined values 
      Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary() 
      newValues( "FileName") = "the name of the file." 
      'Insert the item and rebind 
      e.Item.OwnerTableView.InsertItem(newValues) 
    End If 
End Sub  

Please review this link for more information.

All the best,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Per Holmqvist
Top achievements
Rank 2
Answers by
Per Holmqvist
Top achievements
Rank 2
Georgi Krustev
Telerik team
Share this question
or