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

[Solved] How to edit control properties in insert and edit mode?

3 Answers 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hll
Top achievements
Rank 1
hll asked on 28 Jan 2010, 12:15 PM
Hi,
I have a radupload tool in my RadGrid.
I allow user to upload file when user edits or inserts a row. But when inserting a row, I want user to be able to upload more than one files. On the other hand, when editing a row, I want user to insert just one file.
-This means I should be changing upload tool's property in edit and insert mode of grid-

Here is my grid:
<MasterTableView Width="100%" CommandItemDisplay="Top"
        <Columns> 
            <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn> 
            <telerik:GridTemplateColumn UniqueName="File" HeaderText="Image File"
                 <ItemTemplate> 
                    <asp:Image ID="img" runat="server" Height="50px"/> 
                </ItemTemplate> 
                <EditItemTemplate> 
                        <telerik:RadUpload ID="upload" runat="server" AllowedFileExtensions="gif,jpg,png" AllowedMimeTypes="image/gif,image/jpeg,image/png"></telerik:RadUpload> 
                </EditItemTemplate> 
            </telerik:GridTemplateColumn> 
            <telerik:GridBoundColumn 
                DataField="Title" 
                HeaderText="Title" 
                UniqueName="Title"
            </telerik:GridBoundColumn> 
      </Columns>         
</MasterTableView> 

How can I do that? I added this code below to ItemDataBound method. But it makes MaxFileInputCount=1000 in both edit and insert mode.
MaxFileInputCount should be 1 in edit mode and it should be 1000 in insert mode.

This is the code I wrote to ItemDataBound
if (e.Item is GridEditableItem && e.Item.IsInEditMode && grid.MasterTableView.IsItemInserted) 
            { 
                GridEditableItem temp = e.Item as GridEditableItem; 
                ((RadUpload)temp["File"].FindControl("upload")).MaxFileInputsCount = 1000; 
                ((RadUpload)temp["File"].FindControl("upload")).InitialFileInputsCount = 1; 
 
            } 



3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Jan 2010, 01:07 PM
Hello,

You can use the following code snippet in order to set the maximum file inputs for upload in edit and insert mode.

CS:
 
 
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    {       
            if (e.Item is GridEditableItem && e.Item.IsInEditMode && !RadGrid1.MasterTableView.IsItemInserted) 
            { 
                GridEditableItem temp = e.Item as GridEditableItem; 
                ((RadUpload)temp["File"].FindControl("upload")).MaxFileInputsCount = 1; 
            } 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode  && RadGrid1.MasterTableView.IsItemInserted) 
            { 
                GridEditableItem temp = e.Item as GridEditableItem; 
                ((RadUpload)temp["File"].FindControl("upload")).MaxFileInputsCount = 1000; 
            }      
    } 

-Shinu.
0
hll
Top achievements
Rank 1
answered on 28 Jan 2010, 01:20 PM
Hi,
Thank you for quick reply.

But it is not working in my case because;
if i click 'Add New Item', and without canceling it if i click 'Edit' in one of the rows as well ---> the 'gridAssets.MasterTableView.IsItemInserted' will be true, because 'add' and 'edit' part of grid are open at the same time. (So it will always enter to second if statement.)

Is there anything I can do about this?
0
hll
Top achievements
Rank 1
answered on 28 Jan 2010, 04:28 PM
So any ideas? Or I can not do it?
Tags
Grid
Asked by
hll
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
hll
Top achievements
Rank 1
Share this question
or