How to dynamically show a fileUpload control within a datagrid row on row select or SelectedIndexChanged?

2 posts, 0 answers
  1. Vince
    Vince avatar
    7 posts
    Member since:
    Jan 2013

    Posted 23 May 2018 Link to this post

    I am having problems trying to get a radAsyncUpload control to show up in a row of a radGrid when the row is selected by clicking anyplace on that row.  I am guessing I need to toggle the radGrid into Edit mode once a row is selected?  I have the radAsyncUpload control in the EditItemTemplate of the radGrid for the "Upload" column.  I would then like for the single upload to be performed before any other row may be selected to upload another file.

    RadPageView4 is the section in question.

    .aspx

    001.<telerik:RadTabStrip RenderMode="Lightweight" ID="rdTab" runat="server" Orientation="HorizontalTop"Align="Left" MultiPageID="RadMultiPage2" SelectedIndex="0">
    002.    <Tabs>
    003.        <telerik:RadTab Text="Status" Selected="True" ImageUrl="~/images/RedDot.png" ></telerik:RadTab>
    004.        <telerik:RadTab Text="Ship Group"></telerik:RadTab>
    005.        <telerik:RadTab Text="Tube Groups"></telerik:RadTab>
    006.        <telerik:RadTab Text="Regulatory Work"></telerik:RadTab>
    007.    </Tabs>
    008.</telerik:RadTabStrip>
    009. 
    010.<telerik:RadMultiPage ID="RadMultiPage2" runat="server" SelectedIndex="0" Width="50%">
    011.        <telerik:RadPageView ID="RadPageView1" runat="server" Width="100%">
    012.            <br/>
    013.            Approved: <asp:Label ID="lblApproved" runat="server" Text="False"></asp:Label>
    014.            <br/><br/>
    015.            <asp:Button ID="btnApproval" runat="server" Text="Submit Approval" Enabled="False"/>
    016.        </telerik:RadPageView>
    017. 
    018.        <telerik:RadPageView ID="RadPageView2" runat="server" Width="100%">
    019.        <asp:DetailsView ID="dvShipGroups" runat="server" DataSourceID="sqldsDVSG"AutoGenerateRows="False" DefaultMode="ReadOnly" DataKeyNames="SGID"
    020.                         BorderStyle="None" Width="250px" CellPadding="3" GridLines="None"CellSpacing="2" InsertRowStyle-Wrap="False" RowStyle-Wrap="False">
    021.            <FieldHeaderStyle Wrap="False" HorizontalAlign="Left" />
    022.            <Fields>
    023.                <asp:BoundField DataField="SGID" HeaderText="Ship Group#:" ReadOnly="True">
    024.                </asp:BoundField>
    025.                <asp:BoundField DataField="isApproved" HeaderText="Approved:"ReadOnly="True">
    026.                </asp:BoundField>
    027.                <asp:BoundField DataField="Qty" HeaderText="Qty:" ReadOnly="True">
    028.                </asp:BoundField>
    029.                <asp:BoundField DataField="ShipFromGLID" HeaderText="Ship From:"ReadOnly="True">
    030.                </asp:BoundField>
    031.                <asp:BoundField DataField="ShipToGLID" HeaderText="Ship To:"ReadOnly="True">
    032.                </asp:BoundField>
    033.                <asp:BoundField DataField="ShipDate" HeaderText="ShipDate:"DataFormatString="{0:MM/dd/yyyy}" ReadOnly="True">
    034.                </asp:BoundField>
    035.                <asp:BoundField DataField="ShipDocName" HeaderText="Shipment Form:"ReadOnly="True">
    036.                </asp:BoundField>
    037.                <asp:BoundField DataField="isRegWorkDone" HeaderText="Reg Work Done:"ReadOnly="True">
    038.                </asp:BoundField>
    039.                <asp:BoundField DataField="isShipped" HeaderText="Shipped:" ReadOnly="True"></asp:BoundField>
    040.            </Fields>
    041.        </asp:DetailsView>
    042.    </telerik:RadPageView>
    043. 
    044.    <telerik:RadPageView ID="RadPageView3" runat="server" Width="100%">
    045.        <telerik:RadGrid ID="rgTG" runat="server" RenderMode="Lightweight"AutoGenerateColumns="False" CellSpacing="-1" AllowSorting="True" width="100%" Visible="True"
    046.                     AllowAutomaticUpdates="True" DataSourceID="sqldsRGTG" >
    047.            <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
    048.            <ClientSettings  EnableRowHoverStyle="True" Selecting-AllowRowSelect="True"EnablePostBackOnRowClick="True">
    049.                <Scrolling AllowScroll="False" UseStaticHeaders="False"/>
    050.            </ClientSettings>
    051.            <MasterTableView DataSourceID="sqldsRGTG" DataKeyNames="TGID"EditMode="InPlace" CssClass="MyGridClass">
    052.                <Columns>
    053.                    <telerik:GridBoundColumn DataField="TGID" HeaderText="TGID"SortExpression="TGID" UniqueName="TGID" ReadOnly="True">
    054.                    </telerik:GridBoundColumn>
    055.                    <telerik:GridBoundColumn DataField="CreatedBy" HeaderText="Created By" SortExpression="CreatedBy" UniqueName="CreatedBy" ReadOnly="True">
    056.                    </telerik:GridBoundColumn>
    057.                    <telerik:GridBoundColumn DataField="Qty" HeaderText="Qty"SortExpression="Qty" UniqueName="Qty" ReadOnly="True">
    058.                    </telerik:GridBoundColumn>
    059.                </Columns>
    060.            </MasterTableView>
    061.            <FilterMenu RenderMode="Lightweight"></FilterMenu>
    062.            <HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu>
    063.        </telerik:RadGrid>
    064.    </telerik:RadPageView>
    065. 
    066.    <telerik:RadPageView ID="RadPageView4" runat="server" Width="100%">
    067.        <telerik:RadGrid ID="rgRegWork" runat="server" RenderMode="Lightweight"AutoGenerateColumns="False" CellSpacing="-1" AllowSorting="True" width="100%" Visible="True"
    068.                         AllowAutomaticUpdates="True" DataSourceID="sqldsRGRW"CssClass="MyGridClass">
    069.                <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
    070.                <ClientSettings  EnableRowHoverStyle="True" Selecting-AllowRowSelect="True"EnablePostBackOnRowClick="True">
    071.                    <Scrolling AllowScroll="False" UseStaticHeaders="False" />
    072.                    <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true"AllowResizeToFit="true" />
    073.                </ClientSettings>
    074.                <MasterTableView DataSourceID="sqldsRGRW" DataKeyNames="RWID"EditMode="InPlace" CssClass="MyGridClass">
    075.                    <Columns>
    076.                        <telerik:GridBoundColumn DataField="RWID" HeaderText="RWID"SortExpression="RWID" UniqueName="RWID" ReadOnly="True">
    077.                        </telerik:GridBoundColumn>
    078.                        <telerik:GridBoundColumn DataField="RegulatoryWork"HeaderText="Regulatory Work" SortExpression="RegulatoryWork" UniqueName="RegulatoryWork"ReadOnly="True">
    079.                        </telerik:GridBoundColumn>
    080.                        <telerik:GridTemplateColumn UniqueName="Upload"HeaderText="File Upload" Visible="True">
    081.                            <ItemTemplate>
    082.                                  
    083.                            </ItemTemplate>
    084.                            <EditItemTemplate>
    085.                                <telerik:RadAsyncUpload RenderMode="Lightweight"ID="RadAsyncUpload1" TargetFolder="Uploads" HideFileInput="True" DisablePlugins="true"
    086.                                    AllowedFileExtensions="pdf" MaxInput="1"runat="server" OnFileUploaded="rauFileUpload_FileUploaded"
    087.                                    MultipleFileSelection="Disabled"OverwriteExistingFiles="true" ></telerik:RadAsyncUpload>
    088.                            </EditItemTemplate>
    089.                        </telerik:GridTemplateColumn>
    090.                        <telerik:GridBoundColumn DataField="UpFName" HeaderText="File Name" SortExpression="UpFName" UniqueName="UpFName" ReadOnly="True">
    091.                        </telerik:GridBoundColumn>
    092.                    </Columns>
    093.                </MasterTableView>
    094.                <FilterMenu RenderMode="Lightweight"></FilterMenu>
    095.                <HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu>
    096.         </telerik:RadGrid>
    097.         <asp:Button ID="btnUpload" runat="server" Text="Upload Files" />
    098.    </telerik:RadPageView>
    099.</telerik:RadMultiPage>

    .aspx.vb

    01.Private Sub rgRegWork_SelectedIndexChanged(sender As Object, e As EventArgs) HandlesrgRegWork.SelectedIndexChanged
    02. 
    03.        Dim dataItem As GridDataItem =CType(rgRegWork.SelectedItems(rgRegWork.SelectedItems.Count - 1), GridDataItem)
    04.        Dim RWID As String = dataItem.GetDataKeyValue("RWID").ToString()
    05. 
    06.        'dataitem.Rows(rowIndex).RowState = DataControlRowState.Edit
    07. 
    08.        'For Each selectedItem As GridDataItem In rgRegWork.SelectedItems
    09.        '    Dim index As Integer = selectedItem.ItemIndex
    10.        'Next
    11. 
    12.        'For Each item In rgRegWork.MasterTableView.Items
    13.        '    'rgRegWork.Rows(rowIndex).RowState = DataControlRowState.Edit
    14.        '    Dim editableItem = TryCast(item, GridEditableItem)
    15. 
    16.        '    If editableItem Is Nothing Then
    17.        '       editableItem.Edit = True
    18.        '        rgRegWork.Rebind()
    19.        '    End if
    20.        'Next
    21. 
    22.        'rgRegWork.MasterTableView.EditMode = GridEditMode.EditForms
    23. 
    24.        'Dim rowIndex As Integer = rgRegWork.GridViewRow.RowIndex
    25.        'rgRegWork.SelectedIndex = rowIndex
    26.        'Me.EditIndex = rowIndex
    27.        'Me.Rows(rowIndex).RowState = DataControlRowState.Edit
    28. 
    29. 
    30.        'For Each item In rgRegWork.MasterTableView.Items
    31.        '    Dim editableItem = TryCast(item, GridEditableItem)
    32.        '    If editableItem Is Nothing Then Continue For
    33.        '    editableItem.Edit = True
    34.        '    rgRegWork.Rebind()
    35.        'Next
    36. 
    37.    End Sub
    38. 
    39. 
    40. Protected Sub rauFileUpload_FileUploaded(ByVal sender As Object, ByVal e AsTelerik.Web.UI.FileUploadedEventArgs)
    41. 
    42.        Using conn As NewSqlConnection(ConfigurationManager.ConnectionStrings("CassavaSeedTrackerConnectionString").ConnectionString)
    43.            conn.Open()
    44.            'Dim sql As String = "UPDATE [RegWorkDetail] SET UpFName=@FName WHERE SGID=@SGID AND RWID=@RWID"
    45.            Dim sql As String = "UPDATE [RegWorkDetail] SET UpFName=@FName WHERE SGID=@SGID"
    46.            Dim cmd As New SqlCommand(sql, conn)
    47.            cmd.Parameters.AddWithValue("@FName", e.File.getName())
    48.            cmd.Parameters.AddWithValue("@SGID", Session("sSGID"))
    49.            'cmd.Parameters.AddWithValue("@RWID", Session("sSGID"))
    50.            cmd.ExecuteNonQuery()
    51.            sqldsRGRW.SelectCommand = "SELECT rw.*, rwd.UpFName FROM [RegWork] rw LEFT JOIN [RegWorkDetail] rwd ON rw.RWID=rwd.RWID WHERE GLID = (SELECT ShipToGLID FROM [ShipGroups] WHERE SGID=@SGID) AND rwd.SGID=@SGID"
    52.            sqldsRGRW.SelectParameters.Clear()
    53.            sqldsRGRW.SelectParameters.Add("SGID", CType(Session("sSGID"), String))
    54.            sqldsRGRW.DataBind()
    55.        End Using
    56.         
    57.    End Sub

    01.Private Sub rgRegWork_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rgRegWork.SelectedIndexChanged
    02. 
    03.        Dim dataItem As GridDataItem = CType(rgRegWork.SelectedItems(rgRegWork.SelectedItems.Count - 1), GridDataItem)
    04.        Dim RWID As String = dataItem.GetDataKeyValue("RWID").ToString()
    05. 
    06.        'dataitem.Rows(rowIndex).RowState = DataControlRowState.Edit
    07. 
    08.        'For Each selectedItem As GridDataItem In rgRegWork.SelectedItems
    09.        '    Dim index As Integer = selectedItem.ItemIndex
    10.        'Next
    11. 
    12.        'For Each item In rgRegWork.MasterTableView.Items
    13.        '    'rgRegWork.Rows(rowIndex).RowState = DataControlRowState.Edit
    14.        '    Dim editableItem = TryCast(item, GridEditableItem)
    15. 
    16.        '    If editableItem Is Nothing Then
    17.        '       editableItem.Edit = True
    18.        '        rgRegWork.Rebind()
    19.        '    End if
    20.        'Next
    21. 
    22.        'rgRegWork.MasterTableView.EditMode = GridEditMode.EditForms
    23. 
    24.        'Dim rowIndex As Integer = rgRegWork.GridViewRow.RowIndex
    25.        'rgRegWork.SelectedIndex = rowIndex
    26.        'Me.EditIndex = rowIndex
    27.        'Me.Rows(rowIndex).RowState = DataControlRowState.Edit
    28. 
    29. 
    30.        'For Each item In rgRegWork.MasterTableView.Items
    31.        '    Dim editableItem = TryCast(item, GridEditableItem)
    32.        '    If editableItem Is Nothing Then Continue For
    33.        '    editableItem.Edit = True
    34.        '    rgRegWork.Rebind()
    35.        'Next
    36. 
    37.    End Sub
    38. 
    39. 
    40. Protected Sub rauFileUpload_FileUploaded(ByVal sender As Object, ByVal e As Telerik.Web.UI.FileUploadedEventArgs)
    41. 
    42.        Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("CassavaSeedTrackerConnectionString").ConnectionString)
    43.            conn.Open()
    44.            'Dim sql As String = "UPDATE [RegWorkDetail] SET UpFName=@FName WHERE SGID=@SGID AND RWID=@RWID"
    45.            Dim sql As String = "UPDATE [RegWorkDetail] SET UpFName=@FName WHERE SGID=@SGID"
    46.            Dim cmd As New SqlCommand(sql, conn)
    47.            cmd.Parameters.AddWithValue("@FName", e.File.getName())
    48.            cmd.Parameters.AddWithValue("@SGID", Session("sSGID"))
    49.            'cmd.Parameters.AddWithValue("@RWID", Session("sSGID"))
    50.            cmd.ExecuteNonQuery()
    51.            sqldsRGRW.SelectCommand = "SELECT rw.*, rwd.UpFName FROM [RegWork] rw LEFT JOIN [RegWorkDetail] rwd ON rw.RWID=rwd.RWID WHERE GLID = (SELECT ShipToGLID FROM [ShipGroups] WHERE SGID=@SGID) AND rwd.SGID=@SGID"
    52.            sqldsRGRW.SelectParameters.Clear()
    53.            sqldsRGRW.SelectParameters.Add("SGID", CType(Session("sSGID"), String))
    54.            sqldsRGRW.DataBind()
    55.        End Using
    56.         
    57.    End Sub
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5429 posts

    Posted 28 May 2018 Link to this post

    Hi,

    In addition to one example provided in your support ticket on this (https://www.telerik.com/forums/radasyncupload-in-radgrid#t0IUXUDUK0eQ-xw2vs9agg), I can also suggest you take a look at the following forum thread you can find examples of how to use the client API of the grid to put rows in edit mode with a click: https://www.telerik.com/forums/rad-grid-click-row-for-editing-and-updating. It also shows how you can keep the item in edit mode if some conditions are not met (e.g., no files uploaded or other validation failing). Before opening a new row for editing you can traverse the grid DOM to see if there is a row in edit mode (there's usually a table row with the rgEditRow class, you can inspect the rendered HTML if you use special editing modes to see how to make this check otherwise).


    Regards,
    Marin Bratanov
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top