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

[Solved] radcombo and imageupload in grid

3 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
314
Top achievements
Rank 1
314 asked on 24 Mar 2008, 09:39 AM
As my grid is following http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/TemplateFormUpdate/DefaultVB.aspx to do, and I try to insert the FileUpload into  FormTemplate, when I click insert, that's a problem on it

   Protected Sub RadGrid1_ItemInserted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand  
 
             Dim Id As String = "1" 'I am not sure how to get the primary key when insert  
             Dim PhotoFile As FileUpload = CType(RadGrid1.FindControl("PhotoFileUpload"), FileUpload)' I think the findcontrol has a problem, but not sure how to modify  
            InsertedShoperPhoto(Id, PhotoFile)  
    End Sub 

    Public Sub InsertedShoperPhoto(ByVal Id As String, ByVal PhotoFile As FileUpload)  
        If (PhotoFile Is Nothing) Or (Not PhotoFile.HasFile) Then Return  
        Dim fileLen As Integer  
        fileLen = PhotoFile.PostedFile.ContentLength  
        Dim Input(fileLen) As Byte  
        Input = PhotoFile.FileBytes  
 
        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("PLAZAConnectionString").ConnectionString)  
            Using cmd As New SqlCommand("UPDATE ShoperDetail SET Picture = @Photo WHERE spID = @Id", cn)  
                cmd.Parameters.Add("@Id", Data.SqlDbType.NVarChar, 10).Value = Id 
                cmd.Parameters.Add("@Photo", Data.SqlDbType.Image).Value = Input 
                cn.Open()  
                cmd.ExecuteNonQuery()  
            End Using  
        End Using  
    End Sub 


And the other thing, there's two radcombobox and two sqldatasources inside the FormTemplate, there also have a problem when I run

    <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource3" 
                                                    DataTextField="STname" DataValueField="STname" RadComboBoxImagePosition="Right" 
                                                    Skin="WebBlue" SelectedValue='<%# Bind("ShopType", "{0}") %>'>  
                                                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                                    <ExpandAnimation Type="OutQuart" /> 
                                                </telerik:RadComboBox> 
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:PLAZAConnectionString %>" SelectCommand="SELECT DISTINCT [STname] FROM [ShopType]">  
        </asp:SqlDataSource> 

And the second combobox, it will check what client selected in combobox1, and bind this combobox.
 <telerik:RadComboBox ID="RadComboBox2" runat="server" DataSourceID="SqlDataSource4" 
                                                    DataTextField="STCategory" DataValueField="STCategory" RadComboBoxImagePosition="Right" 
                                                    Skin="WebBlue" SelectedValue='<%# Bind("ShopCat", "{0}") %>'>  
                                                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                                    <ExpandAnimation Type="OutQuart" /> 
                                                </telerik:RadComboBox> 
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:PLAZAConnectionString %>" SelectCommand="SELECT [STCategory] FROM [ShopType] WHERE ([STname] = @STname)">  
            <SelectParameters> 
                <asp:ControlParameter ControlID="RadComboBox2" DefaultValue="Shopping" Name="STname" 
                    PropertyName="SelectedValue" Type="String" /> 
            </SelectParameters> 
        </asp:SqlDataSource> 



3 Answers, 1 is accepted

Sort by
0
314
Top achievements
Rank 1
answered on 24 Mar 2008, 01:56 PM
I try to move the sqldatasource3 and 4 outside the radgrid.
The combobox1 is worked, but comobox2 don't worked.....
0
314
Top achievements
Rank 1
answered on 24 Mar 2008, 07:13 PM

I try to modify some sub class, but I don't know why the system cannot get the value in the PhotoUpload. In debug mode, I see the PhotoFile.FileName is null. Please help me

    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand  
 
        If e.CommandName = RadGrid.PerformInsertCommandName Then 
 
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)  
            Dim newValues As Hashtable = New Hashtable  
            Dim PhotoFile As FileUpload = CType(editedItem.FindControl("PhotoUpload"), FileUpload)  
        End If 
        If (e.CommandName = RadGrid.UpdateCommandName) Then 
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)  
            Dim Id As Integer = CInt(CType(editedItem.FindControl("spID"), TextBox).Text)  
            Dim PhotoFile As FileUpload = CType(editedItem.FindControl("PhotoUpload"), FileUpload)  
            UpdateEmployeePhoto(Id, PhotoFile)  
 
        End If 
    End Sub 

0
Vlad
Telerik team
answered on 25 Mar 2008, 07:03 AM
Hello,

Most probably the grid is ajaxified - uploads are not possible with ajax.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
314
Top achievements
Rank 1
Answers by
314
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or