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

trying to upload image file using demo

6 Answers 124 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Chom
Top achievements
Rank 1
Chom asked on 24 Feb 2010, 04:55 PM
Hello

I am trying to upload an image file using radgrid. I have followd the binary image upload in grid demo but my application is a bit diffirent and have tried several methods to accomplish this. I am adding my update parameters and data and calling the update method in code behind from the RadGrid_UpdateCommand.

I have tried putting the upload code in the UpdateCommand,  DataBount and ItemCreated events but I am getting an error with the parameter and I am not sure if I am going on the right track.

Here is the aspx markup:

        <telerik:RadGrid ID="rgSlides" runat="server" GridLines="None" Skin="Hay" PageSize="8" 
            ClientSettings-Scrolling-SaveScrollPosition="true" AllowPaging="True">  
            <HeaderStyle HorizontalAlign="Left" /> 
            <ItemStyle HorizontalAlign="Left" /> 
            <AlternatingItemStyle HorizontalAlign="Left" /> 
            <ClientSettings EnablePostBackOnRowClick="true">  
                <Selecting AllowRowSelect="true" /> 
            </ClientSettings> 
            <PagerStyle Mode="NumericPages" /> 
            <MasterTableView PageSize="5" AutoGenerateColumns="False" DataKeyNames="OrderID" 
                CommandItemDisplay="Top" ShowHeadersWhenNoRecords="true" NoMasterRecordsText="Click New Slide to insert a new slide row." EditMode="PopUp">  
                <Columns> 
                    <telerik:GridButtonColumn CommandName="DeleteRow" CommandArgument="DeleteRow" HeaderText="" 
                        Text="Delete" UniqueName="DeleteRow">  
                    </telerik:GridButtonColumn> 
                    <telerik:GridTemplateColumn UniqueName="ID" SortExpression="ID" ReadOnly="true" Visible="false">  
                        <ItemTemplate> 
                            <asp:Label ID="lblID" runat="server" Text='<% #Bind("ID") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="CustomerID" UniqueName="CustomerID" SortExpression="CustomerID" Visible="false">  
                    <ItemTemplate> 
                        <asp:Label ID="lblCustomerID" runat="server" Text='<%#Bind("CustomerID") %>' /> 
                    </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="OrderID" UniqueName="OrderID" SortExpression="OrderID" Visible="false">  
                        <ItemTemplate> 
                            <asp:Label ID="lblOrderID" runat="server" Text='<%# Bind("OrderID") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="Business Number" UniqueName="BusinessListingNumber" SortExpression="BusinessListingNumber">  
                        <ItemTemplate> 
                            <asp:Label ID="lblBusinessListingNumber" runat="server" Text='<%# Bind("BusinessListingNumber") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="Slide ID" UniqueName="SlideID" SortExpression="SlideID">  
                        <ItemTemplate> 
                            <asp:Label ID="lblSlideID" runat="server" Text='<%# Bind("SlideID") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="FileName" UniqueName="FileName" SortExpression="FileName" Visible="false">  
                        <ItemTemplate> 
                            <asp:Label ID="lblFileName" runat="server" Text='<%# Bind("FileName") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="Title" UniqueName="Title" SortExpression="Title">  
                        <ItemTemplate> 
                            <asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>' /> 
                        </ItemTemplate> 
                        <EditItemTemplate> 
                            <asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("Title") %>' /> 
                        </EditItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="Description" UniqueName="Description" SortExpression="Description">  
                    <ItemTemplate> 
                    <asp:Label ID="lblDescription" runat="server" Text='<%# Bind("Description") %>'></asp:Label> 
                    </ItemTemplate> 
                        <EditItemTemplate> 
                            <asp:TextBox ID="txtDescription" runat="server" Text='<%# Bind("Description") %>' Width="350px" Height="50px" TextMode="MultiLine" />                              
                        </EditItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridBinaryImageColumn DataField="ImageData" HeaderText="Slide" UniqueName="Upload" ImageAlign="NotSet"   
                    ImageHeight="80px" ImageWidth="80px" ResizeMode="Fit" DataAlternateTextField="Description" DataAlternateTextFormatString="Image od {0}">  
                    <HeaderStyle Width="10%" /> 
                    </telerik:GridBinaryImageColumn> 
                    <%--<telerik:GridTemplateColumn Visible="false">  
                    <EditItemTemplate> 
                        <telerik:RadUpload ID="RadUpload1" runat="server">  
                        </telerik:RadUpload> 
                    </EditItemTemplate> 
                    </telerik:GridTemplateColumn>--%> 
                    <telerik:GridEditCommandColumn>                    
                    </telerik:GridEditCommandColumn> 
                </Columns> 
 
<EditFormSettings CaptionFormatString="Update Slide Info for SlideID: {0}" CaptionDataField="SlideID"   
FormCaptionStyle-Font-Bold="true" PopUpSettings-Modal="true" PopUpSettings-Height="220" PopUpSettings-Width="450px">  
<EditColumn UniqueName="EditCommandColumn1" ButtonType="PushButton">  
</EditColumn> 
</EditFormSettings> 
                <PagerStyle Mode="NextPrev" /> 
                <CommandItemTemplate> 
                    <table style="float: left; width: 100%;">  
                        <tr> 
                            <td style="text-align: left">  
                                <asp:Button ID="btnInsertNewRecord" runat="server" CommandName="InsertNewRecord" 
                                    Text="New Slide" Width="90px" Height="22px" /> 
                            </td> 
                            <td style="text-align: right">  
                                <asp:Button ID="btnRefresh" runat="server" CommandName="Refresh" Text="Refresh" Height="22px" /> 
                            </td> 
                        </tr> 
                    </table> 
                </CommandItemTemplate> 
            </MasterTableView> 
        </telerik:RadGrid> 
        <br /><br /> 
        <asp:Label ID="lblTemplate" runat="server" Text="Template Label"></asp:Label> 
        <br /> 
        <br /> 
        <asp:Label ID="lblSlidesTest" runat="server" ForeColor="Blue" /> 
        <asp:SqlDataSource ID="dsSlides" runat="server" ConnectionString="<%$ myconnectionstring %>"   
        SelectCommand="admin_Customers_BusinessListings_Slides_SelectSlideInfo_1" SelectCommandType="StoredProcedure"   
        InsertCommand="admin_Customers_BusinessListings_Slides_InsertPrimaryInfo" InsertCommandType="StoredProcedure"   
        DeleteCommand="admin_Customers_BusinessListings_Slides_DeleteSlideRow_1" DeleteCommandType="StoredProcedure"   
        UpdateCommand="admin_Customers_BusinessListings_Slides_UpdateSlideInfo_1" UpdateCommandType="StoredProcedure">  
        <SelectParameters> 
        <asp:Parameter Name="CustomerID" /> 
        <asp:Parameter Name="OrderID" /> 
        <asp:Parameter Name="BusinessListingNumber" /> 
        </SelectParameters> 
        <InsertParameters> 
        <asp:Parameter Name="CustomerID" Type="String" /> 
        <asp:Parameter Name="OrderID" Type="String" /> 
        <asp:Parameter Name="BusinessListingNumber" Type="Int16" /> 
        </InsertParameters> 
        <DeleteParameters> 
        <asp:Parameter Name="CustomerID" Type="String" /> 
        <asp:Parameter Name="OrderID" Type="String" /> 
        <asp:Parameter Name="SlideID" Type="String" /> 
        <asp:Parameter Name="BusinessListingNumber" Type="Int16" /> 
        </DeleteParameters> 
        <UpdateParameters> 
        <asp:Parameter Name="CustomerID" Type="String" /> 
        <asp:Parameter Name="OrderID" Type="String" /> 
        <asp:Parameter Name="SlideID" Type="String" /> 
        <asp:Parameter Name="BusinessListingNumber" Type="Int16" /> 
        <asp:Parameter Name="Title" Type="String" /> 
        <asp:Parameter Name="Description" Type="String" /> 
        <asp:Parameter Name="ImageData" Type="Byte"/> 
        </UpdateParameters> 
        </asp:SqlDataSource> 

and here is the code behind:

    Protected Sub rgSlides_UpdateCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgSlides.UpdateCommand  
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then 
            'Get the value of the controls inside the grid template  
            Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
            Dim CustomerID As String = TryCast(editItem("CustomerID").FindControl("lblCustomerID"), Label).Text  
            Dim OrderID As String = TryCast(editItem("OrderID").FindControl("lblOrderID"), Label).Text  
            Dim SlideID As String = TryCast(editItem("SlideID").FindControl("lblSlideID"), Label).Text  
            Dim BusListNo As String = TryCast(editItem("BusinessListingNumber").FindControl("lblBusinessListingNumber"), Label).Text  
 
            'Get the value of the controls inside in the edit form  
            Dim editFormItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)  
            Dim Title As String = DirectCast(editFormItem.FindControl("txtTitle"), TextBox).Text  
            Dim Desc As String = DirectCast(editFormItem.FindControl("txtDescription"), TextBox).Text  
 
            'Update the slide  
            Dim upload As RadUpload = DirectCast(editItem.EditManager.GetColumnEditor("Upload"), GridBinaryImageColumnEditor).RadUploadControl  
 
            'Fill update param's and call update method  
            dsSlides.UpdateParameters("CustomerID").DefaultValue = CustomerID  
            dsSlides.UpdateParameters("OrderID").DefaultValue = OrderID  
            dsSlides.UpdateParameters("SlideID").DefaultValue = SlideID  
            dsSlides.UpdateParameters("BusinessListingNumber").DefaultValue = BusListNo  
            dsSlides.UpdateParameters("Title").DefaultValue = Title  
            dsSlides.UpdateParameters("Description").DefaultValue = Desc  
            dsSlides.UpdateParameters("ImageData").DefaultValue = upload  
            dsSlides.Update()  
        End If 
    End Sub 
 
    Protected Sub rgSlides_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgSlides.ItemDataBound  
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then 
            Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
            Dim upload As RadUpload = DirectCast(editItem.EditManager.GetColumnEditor("Upload"), GridBinaryImageColumnEditor).RadUploadControl  
 
        End If 
    End Sub 
 
    Protected Sub rgSlides_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgSlides.ItemCreated  
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then 
            Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
            Dim upload As RadUpload = DirectCast(editItem.EditManager.GetColumnEditor("Upload"), GridBinaryImageColumnEditor).RadUploadControl  
 
        End If 
    End Sub 

I have some duplicated code in the Update, ItemCreated and ItemDataBound events as I am not sure where to go.

Many thanks

Chommy






6 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 25 Feb 2010, 09:11 AM
Hi Chommy,

You can review this RadListView online demo as it is illustrating similar scenario of how to manually handle the file upload and update the DB. Although it is not a RadGrid example it will give you an idea of the approach which can be used.

Sincerely yours,
Rosen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Chom
Top achievements
Rank 1
answered on 25 Feb 2010, 03:31 PM
Hi Rosen

Is there a way to hide/disable the RadUpload control in the binary image control that is visible when in the edit form when in edit mode?

Thanks

Chommy
0
Chom
Top achievements
Rank 1
answered on 01 Mar 2010, 01:33 AM
Hi Rosen

I looked at the List view demo and have tried to implement the example but I still have no luck. I have surfed through the forums and tried to get a gripe from other examples and I am still struggling to get this to work for me. Is there any other way that I can get some more info on this as I have been busy with this problem for over a week now.

I have been able to upload a file using the RadUploader on a different page and am seeing the <Binary data> in my SQL2005 db table. When I try to view this in the grid using the grid I get an error.

I have tried to start small and then add items and controls as they work for me, but nothing is working. I tried adding a RadUpload in the GridTemplate/EditItemTemplate but am not sure if I am finding the control and not sure how to disable the Ajax relative to the Uploader when a postback occurs.

This has been a frustrating experience so far and I am not sure which avenue to persue. I need to get this resolved so that I can move on.

Thanks
Chommy
0
Rosen
Telerik team
answered on 01 Mar 2010, 02:18 PM
Hi Chommy,

Please find attached a small sample which illustrates a basic implementation of the desired functionality using Northwind database.

All best,
Rosen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Chom
Top achievements
Rank 1
answered on 01 Mar 2010, 11:48 PM
Hi Rosen

Thank you very much for your help. I have created a test app using the model you sent and have hooked it up to my DB. It is working great and I can upload and view the images in the grid.

(Forgive my ignorance here but I am new to these controls and I come from a PLC industrial programming environment which is a lot different than this.)

However when I try to wire it up with all the other code I am able to view the images in the grid but I cannot upload any images. I have several input paramters that I am using in the RadGrid_UpdateCommand and am trying to figure out how to get them from the template fields into the SqlDataSource_Update event etc. I have also bound to my datasource using the RadGrid_NeedDataSource event.

The approach I am trying to do right now is to create another function that will access the items in the grid and then call that function from the SqlDataSource_Updating event to fill those parameters. I am not sure of the syntax and am getting a errors both in the function and the SqlDataSource_Updating event. I have put all items in a hashtable but it looks like I am not getting any values from the function call.

Here is what I have:
        <telerik:RadGrid ID="rgSlides" runat="server" GridLines="None" Skin="Hay" PageSize="8" 
            ClientSettings-Scrolling-SaveScrollPosition="true" AllowPaging="True">  
            <HeaderStyle HorizontalAlign="Left" /> 
            <ItemStyle HorizontalAlign="Left" /> 
            <AlternatingItemStyle HorizontalAlign="Left" /> 
            <ClientSettings EnablePostBackOnRowClick="true">  
                <Selecting AllowRowSelect="true" /> 
            </ClientSettings> 
            <PagerStyle Mode="NumericPages" /> 
            <MasterTableView PageSize="3" AutoGenerateColumns="False" DataKeyNames="OrderID" 
                CommandItemDisplay="Top" ShowHeadersWhenNoRecords="true"   
                NoMasterRecordsText="Click New Slide to insert a new slide row."   
                EditMode="PopUp">  
                <Columns> 
                    <telerik:GridButtonColumn CommandName="DeleteRow" CommandArgument="DeleteRow" HeaderText="" 
                        Text="Delete" UniqueName="DeleteRow">  
                    </telerik:GridButtonColumn> 
                    <telerik:GridTemplateColumn UniqueName="ID" SortExpression="ID" ReadOnly="true" Visible="false">  
                        <ItemTemplate> 
                            <asp:Label ID="lblID" runat="server" Text='<% #Bind("ID") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="CustomerID" UniqueName="CustomerID" SortExpression="CustomerID" Visible="false">  
                    <ItemTemplate> 
                        <asp:Label ID="lblCustomerID" runat="server" Text='<%#Bind("CustomerID") %>' /> 
                    </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="OrderID" UniqueName="OrderID" SortExpression="OrderID" Visible="false">  
                        <ItemTemplate> 
                            <asp:Label ID="lblOrderID" runat="server" Text='<%# Bind("OrderID") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="Business Number" UniqueName="BusinessListingNumber" SortExpression="BusinessListingNumber">  
                        <ItemTemplate> 
                            <asp:Label ID="lblBusinessListingNumber" runat="server" Text='<%# Bind("BusinessListingNumber") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="Slide ID" UniqueName="SlideID" SortExpression="SlideID">  
                        <ItemTemplate> 
                            <asp:Label ID="lblSlideID" runat="server" Text='<%# Bind("SlideID") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="FileName" UniqueName="FileName" SortExpression="FileName" Visible="false">  
                        <ItemTemplate> 
                            <asp:Label ID="lblFileName" runat="server" Text='<%# Bind("FileName") %>' /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="Title" UniqueName="Title" SortExpression="Title">  
                        <ItemTemplate> 
                            <asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>' /> 
                        </ItemTemplate> 
                        <EditItemTemplate> 
                            <asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("Title") %>' /> 
                        </EditItemTemplate> 
                    </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn HeaderText="Description" UniqueName="Description" SortExpression="Description">  
                    <ItemTemplate> 
                    <asp:Label ID="lblDescription" runat="server" Text='<%# Bind("Description") %>'></asp:Label> 
                    </ItemTemplate> 
                        <EditItemTemplate> 
                            <asp:TextBox ID="txtDescription" runat="server" Text='<%# Bind("Description") %>' 
                                Width="350px" Height="50px" TextMode="MultiLine" /> 
                        </EditItemTemplate> 
                    </telerik:GridTemplateColumn> 
 
                      
                    <telerik:GridBinaryImageColumn DataField="ImageData" DefaultInsertValue="" HeaderText="Slide" 
                        ImageHeight="100px" ImageWidth="100px" ResizeMode="Fit" UniqueName="ImageData">  
                    </telerik:GridBinaryImageColumn> 
                      
                    <telerik:GridEditCommandColumn>                                        
                    </telerik:GridEditCommandColumn>                                       
                </Columns> 
<EditFormSettings CaptionFormatString="Update Slide Info for SlideID: {0}" CaptionDataField="SlideID"   
FormCaptionStyle-Font-Bold="true" PopUpSettings-Modal="true" PopUpSettings-Height="220" PopUpSettings-Width="450px">  
<EditColumn UniqueName="EditCommandColumn1" ButtonType="PushButton">  
</EditColumn> 
 
<FormCaptionStyle Font-Bold="True"></FormCaptionStyle> 
 
<PopUpSettings Modal="True" Height="220px" Width="450px"></PopUpSettings> 
</EditFormSettings> 
                <PagerStyle Mode="NextPrev" /> 
                <CommandItemTemplate> 
                    <table style="float: left; width: 100%;">  
                        <tr> 
                            <td style="text-align: left">  
                                <asp:Button ID="btnInsertNewRecord" runat="server" CommandName="InsertNewRecord" 
                                    Text="New Slide" Width="90px" Height="22px" /> 
                            </td> 
                            <td style="text-align: right">  
                                <asp:Button ID="btnRefresh" runat="server" CommandName="Refresh" Text="Refresh" Height="22px" /> 
                            </td> 
                        </tr> 
                    </table> 
                </CommandItemTemplate> 
            </MasterTableView> 
        </telerik:RadGrid> 
          
        <asp:Label ID="lblSlidesTest" runat="server" ForeColor="Blue" /> 
        <asp:SqlDataSource ID="dsSlides" runat="server" ConnectionString="<%$ ConnectionStrings:hbocdbConnectionString %>"   
        OnUpdating="dsSlides_Updating" 
        SelectCommand="admin_Customers_BusinessListings_Slides_SelectSlideInfo_1" SelectCommandType="StoredProcedure"   
        InsertCommand="admin_Customers_BusinessListings_Slides_InsertPrimaryInfo" InsertCommandType="StoredProcedure"   
        DeleteCommand="admin_Customers_BusinessListings_Slides_DeleteSlideRow_1" DeleteCommandType="StoredProcedure"   
        UpdateCommand="UPDATE [admin_Customers_BusinessListings_Slides] SET [Title] = @Title, [Description] = @Description, [ImageData] = @ImageData WHERE [CustomerID] = @CustomerID AND [OrderID] = @OrderID AND [SlideID] = @SlideID AND [BusinessListingNumber = @BusinessListingNumber]">  
        <SelectParameters> 
        <asp:Parameter Name="CustomerID" /> 
        <asp:Parameter Name="OrderID" /> 
        <asp:Parameter Name="BusinessListingNumber" /> 
        </SelectParameters> 
        <InsertParameters> 
        <asp:Parameter Name="CustomerID" Type="String" /> 
        <asp:Parameter Name="OrderID" Type="String" /> 
        <asp:Parameter Name="BusinessListingNumber" Type="Int16" /> 
        </InsertParameters> 
        <DeleteParameters> 
        <asp:Parameter Name="CustomerID" Type="String" /> 
        <asp:Parameter Name="OrderID" Type="String" /> 
        <asp:Parameter Name="SlideID" Type="String" /> 
        <asp:Parameter Name="BusinessListingNumber" Type="Int16" /> 
        </DeleteParameters> 
        <UpdateParameters> 
        <asp:Parameter Name="CustomerID" DbType="String" /> 
        <asp:Parameter Name="OrderID" DbType="String" /> 
        <asp:Parameter Name="SlideID" DbType="String" /> 
        <asp:Parameter Name="BusinessListingNumber" DbType="Int16" /> 
        <asp:Parameter Name="Title" DbType="String" /> 
        <asp:Parameter Name="Description" DbType="String" /> 
        <asp:Parameter Name="ImageData" DbType="Binary" /> 
        </UpdateParameters> 
        </asp:SqlDataSource> 

Protected Sub rgSlides_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgSlides.UpdateCommand  
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then  
            ''Get the value of the controls inside the grid template  
            'Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
            'Dim CustomerID As String = TryCast(editItem("CustomerID").FindControl("lblCustomerID"), Label).Text  
            'Dim OrderID As String = TryCast(editItem("OrderID").FindControl("lblOrderID"), Label).Text  
            'Dim SlideID As String = TryCast(editItem("SlideID").FindControl("lblSlideID"), Label).Text  
            'Dim BusListNo As String = TryCast(editItem("BusinessListingNumber").FindControl("lblBusinessListingNumber"), Label).Text  
 
            ''Get the value of the controls inside in the edit form  
            'Dim editFormItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)  
            'Dim Title As String = DirectCast(editFormItem.FindControl("txtTitle"), TextBox).Text  
            'Dim Desc As String = DirectCast(editFormItem.FindControl("txtDescription"), TextBox).Text  
 
            ''Fill update param's and call update method  
            'dsSlides.UpdateParameters("CustomerID").DefaultValue = CustomerID 
            'dsSlides.UpdateParameters("OrderID").DefaultValue = OrderID 
            'dsSlides.UpdateParameters("SlideID").DefaultValue = SlideID 
            'dsSlides.UpdateParameters("BusinessListingNumber").DefaultValue = BusListNo 
            'dsSlides.UpdateParameters("Title").DefaultValue = Title 
            'dsSlides.UpdateParameters("Description").DefaultValue = Desc 
            ''dsSlides.UpdateParameters("ImageData").DefaultValue = upload 
            'dsSlides.Update()  
        End If  
    End Sub  
 
    Protected Function UpdateImageField(ByVal gridEditableItem As GridEditableItem) As Byte()  
        Dim bytes As Byte() = (DirectCast(gridEditableItem.EditManager.GetColumnEditor("ImageData"), GridBinaryImageColumnEditor)).UploadedFileContent  
        If bytes Is Nothing OrElse bytes.Length = 0 Then  
            bytes = New Byte() {}  
        End If  
        Return bytes  
    End Function  
 
    Protected Function UpdateEditItemParameters(ByVal editItem As GridEditableItem) As Hashtable  
        Dim myItemParams As New Hashtable  
 
        With myItemParams  
            .Add("CustomerID", TryCast(editItem("CustomerID").FindControl("lblCustomerID"), Label).Text)  
            .Add("OrderID", TryCast(editItem("OrderID").FindControl("lblOrderID"), Label).Text)  
            .Add("SlideID", TryCast(editItem("SlideID").FindControl("lblSlideID"), Label).Text)  
            .Add("BusinessListingNumber", TryCast(editItem("BusinessListingNumber").FindControl("lblBusinessListingNumber"), Label).Text)  
        End With  
 
        Return myItemParams  
    End Function  
 
    Protected Function UpdateEditFormParameters(ByVal editFormItem As GridEditFormItem) As Hashtable  
        Dim myFormParams As New Hashtable  
 
        With myFormParams  
            .Add("Title", DirectCast(editFormItem.FindControl("txtTitle"), TextBox).Text)  
            .Add("Description", DirectCast(editFormItem.FindControl("txtDescription"), TextBox).Text)  
        End With  
 
        Return myFormParams  
    End Function  
 
    Protected Sub dsSlides_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles dsSlides.Updating  
 
        Dim myHash As New Hashtable  
        myHash = UpdateEditItemParameters(TryCast(rgSlides.EditItems(0), GridEditableItem))  
 
        Dim myForm As New Hashtable  
        myForm = UpdateEditFormParameters(TryCast(rgSlides.EditItems(0), GridEditFormItem))  
 
        e.Command.Parameters("@CustomerID").Value = myHash("CustomerID")  
        e.Command.Parameters("@OrderID").Value = myHash("OrderID")  
        e.Command.Parameters("@SlideID").Value = myHash("SlideID")  
        e.Command.Parameters("@BusinessListingNumber").Value = CInt(myHash("BusinessListingNumber"))  
 
        e.Command.Parameters("@Title").Value = myForm("Title")  
        e.Command.Parameters("@Description").Value = myForm("Description")  
 
        Dim photoBytes As Byte() = UpdateImageField(TryCast(rgSlides.EditItems(0), GridEditableItem))  
        e.Command.Parameters("@ImageData").Value = photoBytes 
 
    End Sub  
 
    Protected Sub rgSlides_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgSlides.NeedDataSource  
        If Not Page.IsPostBack Then  
            rgSlides.DataSource = New String() {}  
        Else  
            rgSlides.DataSourceID = "dsSlides" 
        End If  
    End Sub 


Thanks for your help

Chommy
0
Rosen
Telerik team
answered on 04 Mar 2010, 12:19 PM
Chommy,

You should not set RadGrid's datasource in such way. You should either set DataSourceID or use NeedDataSource event. Detailed information on supported ways to populated RadGrid control can be found in our help documentation here.

As to how to extract values from the column's EditTemplateItem. As you are using two-way binding you can use GridEditableItem's ExtractValues method to populate a dictionary with fieldName/value pairs.

Greetings,
Rosen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
BinaryImage
Asked by
Chom
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Chom
Top achievements
Rank 1
Share this question
or