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

retrieving the uploaded file name from RadUpload control which is in radGrid.

3 Answers 337 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ranganath
Top achievements
Rank 1
Ranganath asked on 23 Jul 2008, 11:40 AM

Actually I have taken one RadGrid and in that I have taken one RadUpLoad control in that.

And I want to find out the file name of Uploaded File along with pathname separately. Here I am sending the code which I tried to Implement….

<telerik:RadGrid ID="rgSubmenus" runat="server" AllowPaging="True" GridLines="Horizontal"

                    Skin="Default" OnNeedDataSource="rgSubmenus_NeedDataSource" PageSize="10" Width="70%"

                    OnInsertCommand="rgSubmenus_InsertCommand" OnItemDataBound="rgSubmenus_ItemDataBound"

                    OnUpdateCommand="rgSubmenus_UpdateCommand" >

                    <PagerStyle Mode="Slider" />

                    <MasterTableView CommandItemDisplay="TopAndBottom" AutoGenerateColumns="false" DataKeyNames="submenuid"

                        EditMode="EditForms" CommandItemSettings-AddNewRecordText="Add Submenu">

                        <Columns>

                            <telerik:GridBoundColumn DataField="submenuid" HeaderText="SubMenu ID" HeaderStyle-HorizontalAlign="Center"

                                ItemStyle-HorizontalAlign="Left" Visible="false">

                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn DataField="mainmenuid" HeaderText="MainMenu ID" HeaderStyle-HorizontalAlign="Center"

                                ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="15%" Visible="false">

                            </telerik:GridBoundColumn>

So On…

                            <telerik:GridBoundColumn DataField="url" HeaderText="URL" HeaderStyle-HorizontalAlign="Center"

                                ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="25%">

                            </telerik:GridBoundColumn>

                           

                            <FormTemplate>

                                <table width="100%" cellpadding="0" cellspacing="0" border="0" bordercolor="red">

                                    <tr>

                                        <td width="49%" align="right">

                                            Select MainMenu

                                        </td>

                                        <td width="2%">

                                            :

                                        </td>

                                        So On…..

                                                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

                                            </telerik:RadComboBox>

                                        </td>

                                    </tr>

                                    <tr>

                                        <td width="49%" align="right">

                                            Submenu Name

                                        </td>

                                        <td width="2%">

                                            :

                                        </td>

                                    <tr>

                                        <td width="49%" align="right">

                                            Submenu URL

                                        </td>

                                        <td width="2%">

                                            :

                                        </td>

                                        <td width="49%" align="left">

                                            <telerik:RadUpload ID="rdSubmenuUpload" runat="server" Skin="Default" ControlObjectsVisibility="None"                                         Width="150px" InputSize="25" AllowedFileExtensions=".aspx" />

                                        </td>

                                    </tr>

                                    <tr>

 

So On…

            <td width="49%" align="left">

                                            <asp:Button runat="server" ID="btnAddRoles" Text='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "Insert" : "Update" %>'

                                                CommandName='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "PerformInsert" : "Update" %>'

                                                CssClass="btn1" />&nbsp;&nbsp;

                                            <asp:Button runat="server" ID="btnCancel" Text="Cancel" CssClass="btn1" CausesValidation="false"

                                                CommandName="Cancel" />

                                        </td>

                                    </tr>

                                   

                            </FormTemplate>

                        </EditFormSettings>

                    </MasterTableView>

                </telerik:RadGrid>

 

 

 

 

 

 

I tried C# in the following ways

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

    {

        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))

        {

            GridEditableItem formItem = (GridEditableItem)e.Item;

            RadUpload rdUload = (RadUpload)formItem.FindControl("rdSubmenuUpload");

 

            int a = rdUload.UploadedFiles.Count;

        }

 

    }

 

protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)

    {

        //Get the GridEditFormInsertItem of the RadGrid

         //GridEditFormInsertItem insertedItem = e.Item as GridEditFormInsertItem;

        

        //RadComboBox ddlMainmenu = (insertedItem.FindControl("ddlMainmenus") as RadComboBox);

 

        GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;

        RadUpload ruld = (insertedItem.FindControl("rdSubmenuUpload") as RadUpload);

        int a = ruld.UploadedFiles.Count;

...

 

}

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 24 Jul 2008, 12:08 PM
Hello Ranganath,

RadUpload.UploadedFiles would only work in InsertCommand event handler, because in ItemDataBound files have already been uploaded to the server directory and RadUpload is empty. You can get a reference to the uploaded files in the InsertCommand and ItemInserted events, the first if you need to modify or manually enter the data in the data source, and the second if you want to display a message with information about the uploaded files after insertion:

protected void RadGrid1_ItemInserted(object source, Telerik.Web.UI.GridInsertedEventArgs e) 
    GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item; 
    Response.Write((item.FindControl("RadUpload1"as RadUpload).UploadedFiles.Count); 
    Response.Write((item.FindControl("RadUpload1"as RadUpload).UploadedFiles[0].FileName); 


Best wishes,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ranganath
Top achievements
Rank 1
answered on 24 Jul 2008, 12:45 PM

Hi,

Thanks for response, but I hope u hasn’t seen the code which I was posted 2 days back.

I tried same thing under “RadGrid1_InsertCommand”,but no use.i am nt getting the No Fiels uploaded/FileName.

protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)

{

        GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;

        RadAjaxManager2.Alert((item.FindControl("rdSubmenuUpload") as RadUpload).UploadedFiles.Count.ToString());

..

}

 

Plese guide me in right way.

 

0
Veli
Telerik team
answered on 24 Jul 2008, 01:06 PM
Hello Ranganath,

Please note that RadUpload needs full postbacks to upload the files on the server. If you have ajaxified your RadGrid, you will need to temporarily disable AJAX for your RadGrid during uploading. For more information on the topic, please refer to the following demo example:

Using RadUpload in an Ajaxified Grid

Greetings,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Ranganath
Top achievements
Rank 1
Answers by
Veli
Telerik team
Ranganath
Top achievements
Rank 1
Share this question
or