[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1218
  • Last Modified:

Dynamic GridView to upload files

I have a gridview I am using to upload files to a folder on the server. The datasource below generates a gridview with 25 rows which is a desired number. However I want to be able to specify the amount of rows I want in the datagrid. Say if I wanted 5 rows then I could generate the gridView with 5 rows.

Me.GridView1.DataSource = "{1,2,3,4,5,6,7,8,9,10,11}"
Me.GridView1.DataBind()
0
ruffone
Asked:
ruffone
  • 5
  • 5
2 Solutions
 
Bob LearnedCommented:
Try something like this:

Private m_files As New ArrayList(25)

...

m_files = New ArrayList(fileCount)
Me.GridView1.DataSource = m_files
Me.GridView1.DataBind()

Bob
0
 
ruffoneAuthor Commented:
How do I add the 25 items into the arraylist? I need an example on how to genarate the 25 items based on the number 25.
0
 
Bob LearnedCommented:
>>generate the 25 items
What do you mean by "generate"?  How would an item be generated?

Bob
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ruffoneAuthor Commented:
I am not getting data items from a source. Don't I need to do some kind of a foreach to add the 25 items to the arrayLise?
0
 
Bob LearnedCommented:
It sounds like you asking for a way to create 25 strings that can contain file names that will be uploaded.

Bob
0
 
ruffoneAuthor Commented:
The idea is to have a gridview with do 10, 15, 5 rows as the case my be. so that I could upload multiple files. The fileUpload control in the gridview's itemTemplate. What I need is a way dynamically determine how many rows come up in the gridview. That is all this will be used for. I am foreaching through the gridview row to upload the files. So the dataSource will only be used to set the count of rows in the grid.
0
 
Bob LearnedCommented:
Then, all you need is 25 places to store information, and creating an ArrayList with 25 elements should work, and you don't even need to store anything in the list elements.

Bob
0
 
ruffoneAuthor Commented:
This did it. This is the code I was asking for
        For fileCount = 0 To 24
            m_files.Add(fileCount)
        Next
0
 
Bob LearnedCommented:
Does that mean that you didn't try what I was suggesting?  It should have worked without the for loop.

Bob
0
 
ruffoneAuthor Commented:
it didn't, Here is the source of what worked out for me
<script>
    Private m_files As New ArrayList
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            BindGrid(24)
        End If
    End Sub
    Public Sub BindGrid(ByVal cFiles As Single)
        For fileCount = 0 To cFiles
            m_files.Add(fileCount)
        Next
 
        Me.GridView1.DataSource = m_files
        Me.GridView1.DataBind()
    End Sub
</script>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
    <Columns>
        <asp:TemplateField HeaderText="Select Files to upload">
            <ItemTemplate>
                <asp:FileUpload ID="fileUpload1" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<asp:Button ID="btnUpload" runat="server" Text="Upload Files" />

Open in new window

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now