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()
LVL 4
ruffoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.