RadUpload nested in RadGrid

Thread is closed for posting
6 posts, 0 answers
  1. Daniel Caves
    Daniel Caves avatar
    5 posts
    Member since:
    Jul 2009

    Posted 10 Jul 2009 Link to this post

    Hi -

    I am new to RadControls, and I am having an issue accessing the RadUpload control when it is nested deep inside a RadGrid.

    The RadUpload is inside of a RadMultiPage, in the FormTemplate of a RadGrid.  I am trying to manipulate the uploaded files, but I can't figure out how to get a reference to the RadUpload when my submit button is clicked.  Below is my aspx code for the entire RadGrid:

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"  
                            AllowSorting="True" Skin="Black" 
                            AllowPaging="True" PageSize="5" GridLines="None" DataSourceID="SqlDataSource1" 
                            AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false"  
                            ShowDesignTimeSmartTagMessage="False" ShowGroupPanel="true"
                            <PagerStyle Mode="NumericPages" /> 
                            <MasterTableView CellSpacing="-1" DataKeyNames="IDDepartment" DataSourceID="SqlDataSource1" EditMode="EditForms" 
                                EnableTheming="true" CommandItemDisplay="Top"
                                <EditFormSettings EditFormType="Template"
                                    <FormTemplate> 
                                        <asp:Panel ID="InnerContainer" runat="server" Visible="true" style="padding:15px;"
                                            <telerik:RadTabStrip ID="RadTabStrip1" runat="server"  
                                                MultiPageID="RadMultiPage1" SelectedIndex="0" Skin="Black"
                                                <Tabs> 
                                                    <telerik:RadTab runat="server" PageViewID="RadPageView1" Text="Dept Info"
                                                    </telerik:RadTab> 
                                                    <telerik:RadTab runat="server" PageViewID="RadPageView2" Text="Dept Contacts"
                                                    </telerik:RadTab> 
                                                    <telerik:RadTab runat="server" PageViewID="RadPageView3" Text="Dept Files"  
                                                        Selected="True"
                                                    </telerik:RadTab> 
                                                </Tabs> 
                                            </telerik:RadTabStrip> 
                                            <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0"
                                                <telerik:RadPageView ID="RadPageView1" runat="server" BorderColor="Black"  
                                                    BorderStyle="Solid" BorderWidth="1px"
                                                    <table> 
                                                        <tr> 
                                                            <td> 
                                                                Name:</td> 
                                                            <td> 
                                                                <asp:TextBox ID="Name" runat="server" Text='<%# Bind( "Name" ) %>'></asp:TextBox> 
                                                            </td> 
                                                        </tr> 
                                                        <tr> 
                                                            <td> 
                                                                Description:</td> 
                                                            <td align="center"
                                                                <telerik:RadEditor ID="Description" runat="server" BackColor="White"  
                                                                    HTML='<%# Bind( "Description" ) %>' Skin="Black"
                                                                    <CssFiles> 
                                                                        <telerik:EditorCssFile Value="~/css/Styles1.css" /> 
                                                                    </CssFiles> 
                                                                    <Content> 
                                                                     
                                                                    </Content> 
                                                                </telerik:RadEditor> 
                                                            </td> 
                                                        </tr> 
                                                    </table> 
                                                </telerik:RadPageView> 
                                                <telerik:RadPageView ID="RadPageView2" runat="server" BorderColor="Black"  
                                                    BorderStyle="Solid" BorderWidth="1px"
                                                    <table> 
                                                        <tr> 
                                                            <td></td
                                                            <td>Hold Ctrl to select multiple<br /></td
                                                        </tr> 
                                                        <tr> 
                                                            <td>Contacts:</td> 
                                                            <td> 
                                                                <asp:ListBox ID="lstContacts" runat="server" DataSourceID="SqlDataSource2"  
                                                                    DataTextField="FullName" DataValueField="IDEmployee"  
                                                                    ondatabound="lstContacts_DataBound" SelectionMode="Multiple" Width="250px"></asp:ListBox> 
                                                            </td> 
                                                        </tr> 
                                                    </table> 
                                                </telerik:RadPageView> 
                                                <telerik:RadPageView ID="RadPageView3" runat="server" BorderColor="Black"  
                                                    BorderStyle="Solid" BorderWidth="1px"
                                                    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False"  
                                                        AllowSorting="True" Skin="Black" AllowPaging="True" PageSize="5"  
                                                        GridLines="None" 
                                                        ShowDesignTimeSmartTagMessage="False" ShowGroupPanel="True"  
                                                        onneeddatasource="RadGrid2_NeedDataSource"
                                                        <MasterTableView CellSpacing="-1"
                                                            <RowIndicatorColumn> 
                                                                <HeaderStyle Width="20px" /> 
                                                            </RowIndicatorColumn> 
                                                            <ExpandCollapseColumn> 
                                                                <HeaderStyle Width="20px" /> 
                                                            </ExpandCollapseColumn> 
                                                            <Columns> 
                                                                <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"  
                                                                    ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this record?" 
                                                                    UniqueName="Delete"
                                                                </telerik:GridButtonColumn> 
                                                                <telerik:GridBoundColumn DataField="FileName" HeaderText="File Name"  
                                                                    SortExpression="FileName" UniqueName="FileName"
                                                                </telerik:GridBoundColumn> 
                                                                <telerik:GridBoundColumn DataField="Description" HeaderText="Description"  
                                                                    SortExpression="Description" UniqueName="Description"
                                                                </telerik:GridBoundColumn> 
                                                            </Columns> 
                                                        </MasterTableView> 
                                                    </telerik:RadGrid> 
                                                    
                                                    <table width="100%"
                                                        <tr> 
                                                            <td>Upload file: </td> 
                                                            <td> <div class="FileDetails"
                                                                <telerik:RadUpload ID="RadUpload1" runat="server" MaxFileInputsCount="5"  
                                                                    OnClientAdded="addTitle"  
                                                                    TargetFolder="~/files" EnableFileInputSkinning="true"  
                                                                    ControlObjectsVisibility="RemoveButtons, AddButton" Skin="Black"
                                                                </telerik:RadUpload> 
                                                                <div class="UploadButton"><asp:Button Width="75px" id="buttonSubmit" runat="server" OnClick="buttonSubmit_Click" text="Upload" /></div></div> 
                                                            </td> 
                                                        </tr> 
                                                        <tr> 
                                                            <td align="center" colspan="2"
                                                               <telerik:RadProgressArea ID="RadProgressArea1" runat="server" Skin="Black"
                                                                    <Localization Uploaded="Uploaded" /> 
                                                                </telerik:RadProgressArea> <br /><br /> 
                                                                 
                                                            </td> 
                                                        </tr> 
                                                    </table> 
                                                 
                                                </telerik:RadPageView> 
                                            </telerik:RadMultiPage> 
                                            <table width="100%"
                                                <tr> 
                                                    <td align="center"
                                                        <asp:Button ID="Update" runat="server" Text="Update" CommandName="Update" /> 
                                                        <asp:Button ID="Cancel" runat="server" Text="Cancel" CommandName="Cancel" /> 
                                                    </td> 
                                                </tr> 
                                            </table> 
                                        </asp:Panel> 
                                    </FormTemplate> 
                                </EditFormSettings> 
                                <Columns> 
                                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="Edit"
                                    </telerik:GridEditCommandColumn> 
                                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name"  
                                        SortExpression="Name" UniqueName="Name"
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn DataField="Description" HeaderText="Description"  
                                        SortExpression="Description" UniqueName="Description"
                                    </telerik:GridBoundColumn> 
                                    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"  
                                        ConfirmDialogType="RadWindow"  
                                        ConfirmText="Are you sure you want to delete this record?" Text="Delete"  
                                        UniqueName="Delete"
                                    </telerik:GridButtonColumn> 
                                </Columns> 
                            </MasterTableView> 
                        </telerik:RadGrid> 

    Can someone tell me how to access RadUpload1 from the buttonSubmit_Click event?
  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 13 Jul 2009 Link to this post

    Hello Daniel Caves,

    In order to obtain reference to the upload you can do the following:
    1) hook on the ItemDataBound event of the RadGrid. Once there, use the following code:

     protected void RadGrid1_ItemDataBound(object  sender, GridItemEventArgs e) 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
     RadUpload upload = e.Item.FindControl("RadUpload1"as RadUpload; 
     RadAjaxPanel1.ResponseScripts.Add(string.Format("window['UploadId'] = '{0}';", upload.ClientID)); 
    }  

    Then, on the client hook on the click event of your submit button and use the following code to obtain reference to the RadUpload:


    var upload = $find(window['UploadId']); 


    Greetings,
    Genady Sergeev
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel Caves
    Daniel Caves avatar
    5 posts
    Member since:
    Jul 2009

    Posted 13 Jul 2009 Link to this post

    Hi, thanks for the reply.  I just want to clarify a few things.

    First, are you telling me that I should place the RadUpload inside of a RadAjaxPanel?  And then are you saying I should handle the upload from the client side?  I need to add information to my database with the uploaded file, I'm not sure that is possible from the client side. 

    What I am really looking for is how to obtain a reference to the RadUpload from the server-side Button_Click event.

    Thanks in advance.

    Daniel Caves
  5. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 14 Jul 2009 Link to this post

    Hello Daniel Caves,

    Please excuse me, I have misunderstood your question. You cannot obtain reference of the RadUpload in the click handler. Instead you need to hook on the RadGrid Insert or respectively Update command and use the following syntax:

     
    protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
            { 
                        (RadUpload)e.Item.FindControl("RadUpload1"); 
            } 

    If for some reason you do not want to use the former approach, you can access the uploaded files in the click handler via the RadUploadContext.Current.UploadedFiles property.

    Regards,
    Genady Sergeev
    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.
  6. Pavani
    Pavani avatar
    9 posts
    Member since:
    Jul 2012

    Posted 31 Aug 2012 Link to this post

    Hi,


                I have a Radgird with DropdownList,TextBox and RadAsyncUpload controls. when i select value from dropdown list. iam filling the textbox with a value from the database based on selection. but my problem is when i upload a file and select the dropdown the uploaded file is refreshed. i donot want that uploaded file to be refreshed.if already there is file when binding to rad grid i have to place that file in that upload control. I already placed PostBackTriggers with save button.can you please solve my problem. please see my code.

     

    <telerik:RadGrid ID="rgMoveOutCheckList" runat="server" OnItemDataBound="rgMoveOutCheckList_ItemDataBound"

    AutoGenerateColumns="false" Width="100%">

    <MasterTableView DataKeyNames="UploadedImage">

    <Columns>

    <telerik:GridTemplateColumn UniqueName="AttributeCondition" HeaderStyle-Width="130px" ItemStyle-Width="130px">

    <ItemTemplate>

    <asp:DropDownList ID="ddlCondition" DataTextField="Description" DataValueField="AttributeConditionId" AutoPostBack="true" OnSelectedIndexChanged="ddlCondition_SelectedIndexChanged"

    runat="server" Width="130px">

    </asp:DropDownList>

    <asp:RequiredFieldValidator ID="rfvCondition" runat="server" ControlToValidate="ddlCondition"

    ForeColor="Red" Text="*" InitialValue="0"></asp:RequiredFieldValidator>

    </ItemTemplate>

    </telerik:GridTemplateColumn>

    <telerik:GridTemplateColumn UniqueName="CAmount" HeaderStyle-Width="100px" ItemStyle-Width="100px">

    <ItemTemplate>

    <telerik:RadNumericTextBox ID="rntCAmount" MinValue="0" runat="server" SkinID="Required" Width="80px"></telerik:RadNumericTextBox>

    <asp:RequiredFieldValidator ID="rfvCAmount" runat="server" Text="*" ForeColor="Red"

    ControlToValidate="rntCAmount"></asp:RequiredFieldValidator>

    <asp:CompareValidator ID="cvCAmount" runat="server" ControlToValidate="rntCAmount"

    Text="*" Type="Currency" ForeColor="Red" Operator="DataTypeCheck"></asp:CompareValidator>

    </ItemTemplate>

    </telerik:GridTemplateColumn>

    <telerik:GridTemplateColumn>

    <ItemTemplate>

    <telerik:RadAsyncUpload runat="server" ID="rauAttribute" Width="150px"

    MaxFileInputsCount="1" AllowedFileExtensions="jpeg,jpg,gif,png,bmp" PostbackTriggers="rbSave" />

    </ItemTemplate>

    </telerik:GridTemplateColumn>

    </Columns>

    </MasterTableView>

    </telerik:RadGrid>

     

     

    protected void ddlCondition_SelectedIndexChanged(object sender, EventArgs e)

    {
    DropDownList ddlCondition = (DropDownList)sender;

    GridDataItem item = (GridDataItem)ddlCondition.NamingContainer;

    RadNumericTextBox rntCAmount = (RadNumericTextBox)item.FindControl("rntCAmount");

    DataTable dtCheckList = ViewState["CheckList"] as DataTable;

    DataRow dr;

    string unitTypeRoomTypeId = item.GetDataKeyValue("UnitTypeRoomTypeId").ToString();

    string attributeId = item.GetDataKeyValue("AttributeId").ToString();

    string condition = ddlCondition.SelectedValue;

    dr = dtCheckList.Select(

    "UnitTypeRoomTypeId='" + unitTypeRoomTypeId + "' AND AttributeId='" + attributeId + "'")[0];

    if (dr != null)

    {

    if (condition == "2")

    {

    rntCAmount.Enabled = (

    bool.Parse(dr["IsCleaningChargeEditable"].ToString()));

    rntCAmount.Text = (

    bool.Parse(dr["IsCleaningChargeEditable"].ToString())) ? "0" : dr["DefaultCleaningCharge"].ToString();

    }

    else if (condition == "3")

    {

    rntCAmount.Enabled = (

     

    bool.Parse(dr["IsRepairChargeEditable"].ToString()));

    rntCAmount.Text = (

    bool.Parse(dr["IsRepairChargeEditable"].ToString())) ? "0" : dr["DefaultRepairCharge"].ToString();

    }

    else if (condition == "4")

    {

    rntCAmount.Enabled = (

    bool.Parse(dr["IsReplacementChargeEditable"].ToString()));

    rntCAmount.Text = (

    bool.Parse(dr["IsReplacementChargeEditable"].ToString())) ? "0" : dr["DefaultReplacementCharge"].ToString();

    }

    else

    {

    rntCAmount.Enabled =

    false;

    rntCAmount.Text =

    "0";

    }

    }

    }

  7. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 05 Sep 2012 Link to this post

    Hi Pavani,

    I setup a sample page from the provided code. Please review the attachment. Keep in mind that if you rebind the RadGrid on every postback you cannot keep the uploaded files.

    Regards,
    Peter Filipov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017