populating a datagrid

Discussion in 'ASP .Net Datagrid Control' started by viktor9990, Mar 29, 2005.

  1. viktor9990

    viktor9990 Guest

    I have a datagrid with 2 item templates inside a hyperlink and a label (which
    will show the file name and creation date of files which resides on a folder
    on the server. I'm using a procedure (GetScannedFiles()) to loop and get the
    required information from the folder but don't know how to show this info
    inside my datagrid ( dynamically or from my aspx page). I appreciate any
    help.
    Look my code below.

    Here is the code for( MyDatagrid.aspx):

    <asp:datagrid id="DGFileScanned" runat="server" Autogeneratecolumns="false" >
    <Columns>

    <asp:TemplateColumn HeaderText="File Name">
    <ItemTemplate>
    <div>
    <asp:hyperlink ForeColor="blue" Font-Size="10" id="FileName" runat="server" >
    .....
    </asp:hyperlink></div>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <ItemTemplate>
    <div>
    <asp:Label ID="FileDate" Visible="true" Text="...." Runat="server" />
    </div>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>

    Here is the code behind for (Mydatagrid.aspx.vb)

    Private Sub GetScannedFiles()
    'Name of the folder which holds the scanned TIFF files (agreements
    images)
    Dim FolderPath As String =
    Server.MapPath("/TrackerAggreement/admin/FilesTIFF/")
    Dim source As DirectoryInfo = New DirectoryInfo(FolderPath)

    'Get an array of all scanned TIFF files in the source direcotry
    Dim sourceFiles As FileInfo() = source.GetFiles("*.tiff")
    'Loop to get File Names and Creation Time of the TIFF files in the
    source direcotry
    Dim i As Integer
    For i = 0 To i < (sourceFiles.Length)
    'Get the File Name of every scanned TIFF file
    Dim FileName As String = Path.GetFileName(sourceFiles(i).FullName)
    'Get the Creation Time of every scanned TIFF file
    Dim FileDate As String =
    Path.GetFileName(sourceFiles(i).CreationTime)
    i = i + 1
    Next
    End Sub
    viktor9990, Mar 29, 2005
    #1
    1. Advertising

  2. viktor9990

    Elton Wang Guest

    You can use a datatable to save FileName and FileDate in
    it, and then bind the datagrid's data source with the
    datatable. In the datagrid you can use a HyperLinkColumn
    and a BoundColumn to show file name and file date.

    HTH

    Elton Wang


    >-----Original Message-----
    >I have a datagrid with 2 item templates inside a

    hyperlink and a label (which
    >will show the file name and creation date of files which

    resides on a folder
    >on the server. I'm using a procedure (GetScannedFiles())

    to loop and get the
    >required information from the folder but don't know how

    to show this info
    >inside my datagrid ( dynamically or from my aspx page).

    I appreciate any
    >help.
    >Look my code below.
    >
    >Here is the code for( MyDatagrid.aspx):
    >
    ><asp:datagrid id="DGFileScanned" runat="server"

    Autogeneratecolumns="false" >
    ><Columns>
    >
    ><asp:TemplateColumn HeaderText="File Name">
    ><ItemTemplate>
    ><div>
    ><asp:hyperlink ForeColor="blue" Font-Size="10"

    id="FileName" runat="server" >
    > .....
    ></asp:hyperlink></div>
    ></ItemTemplate>
    ></asp:TemplateColumn>
    ><asp:TemplateColumn>
    ><ItemTemplate>
    ><div>
    ><asp:Label ID="FileDate" Visible="true" Text="...."

    Runat="server" />
    ></div>
    ></ItemTemplate>
    ></asp:TemplateColumn>
    ></Columns>
    ></asp:datagrid>
    >
    >Here is the code behind for (Mydatagrid.aspx.vb)
    >
    > Private Sub GetScannedFiles()
    > 'Name of the folder which holds the scanned TIFF

    files (agreements
    >images)
    > Dim FolderPath As String =
    >Server.MapPath("/TrackerAggreement/admin/FilesTIFF/")
    > Dim source As DirectoryInfo = New DirectoryInfo

    (FolderPath)
    >
    > 'Get an array of all scanned TIFF files in the

    source direcotry
    > Dim sourceFiles As FileInfo() = source.GetFiles

    ("*.tiff")
    > 'Loop to get File Names and Creation Time of the

    TIFF files in the
    >source direcotry
    > Dim i As Integer
    > For i = 0 To i < (sourceFiles.Length)
    > 'Get the File Name of every scanned TIFF file
    > Dim FileName As String = Path.GetFileName

    (sourceFiles(i).FullName)
    > 'Get the Creation Time of every scanned TIFF

    file
    > Dim FileDate As String =
    >Path.GetFileName(sourceFiles(i).CreationTime)
    > i = i + 1
    > Next
    > End Sub
    >.
    >
    Elton Wang, Mar 29, 2005
    #2
    1. Advertising

  3. viktor9990

    viktor9990 Guest

    In my solution I need to populate the datagrid without using the database. Is
    there any solution?Thanks

    "Elton Wang" wrote:

    > You can use a datatable to save FileName and FileDate in
    > it, and then bind the datagrid's data source with the
    > datatable. In the datagrid you can use a HyperLinkColumn
    > and a BoundColumn to show file name and file date.
    >
    > HTH
    >
    > Elton Wang
    >
    >
    > >-----Original Message-----
    > >I have a datagrid with 2 item templates inside a

    > hyperlink and a label (which
    > >will show the file name and creation date of files which

    > resides on a folder
    > >on the server. I'm using a procedure (GetScannedFiles())

    > to loop and get the
    > >required information from the folder but don't know how

    > to show this info
    > >inside my datagrid ( dynamically or from my aspx page).

    > I appreciate any
    > >help.
    > >Look my code below.
    > >
    > >Here is the code for( MyDatagrid.aspx):
    > >
    > ><asp:datagrid id="DGFileScanned" runat="server"

    > Autogeneratecolumns="false" >
    > ><Columns>
    > >
    > ><asp:TemplateColumn HeaderText="File Name">
    > ><ItemTemplate>
    > ><div>
    > ><asp:hyperlink ForeColor="blue" Font-Size="10"

    > id="FileName" runat="server" >
    > > .....
    > ></asp:hyperlink></div>
    > ></ItemTemplate>
    > ></asp:TemplateColumn>
    > ><asp:TemplateColumn>
    > ><ItemTemplate>
    > ><div>
    > ><asp:Label ID="FileDate" Visible="true" Text="...."

    > Runat="server" />
    > ></div>
    > ></ItemTemplate>
    > ></asp:TemplateColumn>
    > ></Columns>
    > ></asp:datagrid>
    > >
    > >Here is the code behind for (Mydatagrid.aspx.vb)
    > >
    > > Private Sub GetScannedFiles()
    > > 'Name of the folder which holds the scanned TIFF

    > files (agreements
    > >images)
    > > Dim FolderPath As String =
    > >Server.MapPath("/TrackerAggreement/admin/FilesTIFF/")
    > > Dim source As DirectoryInfo = New DirectoryInfo

    > (FolderPath)
    > >
    > > 'Get an array of all scanned TIFF files in the

    > source direcotry
    > > Dim sourceFiles As FileInfo() = source.GetFiles

    > ("*.tiff")
    > > 'Loop to get File Names and Creation Time of the

    > TIFF files in the
    > >source direcotry
    > > Dim i As Integer
    > > For i = 0 To i < (sourceFiles.Length)
    > > 'Get the File Name of every scanned TIFF file
    > > Dim FileName As String = Path.GetFileName

    > (sourceFiles(i).FullName)
    > > 'Get the Creation Time of every scanned TIFF

    > file
    > > Dim FileDate As String =
    > >Path.GetFileName(sourceFiles(i).CreationTime)
    > > i = i + 1
    > > Next
    > > End Sub
    > >.
    > >

    >
    viktor9990, Mar 30, 2005
    #3
  4. Here's some code that populates a datagrid from file list. Perhaps it will
    give you the idea?

    Ken
    Microsoft MVP [ASP.NET]
    Toronto

    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    'create file list
    Dim imagepath As String
    imagepath = Server.MapPath("")
    dgfiles.DataSource = _
    System.IO.Directory.GetFiles(imagepath)
    dgfiles.DataBind()

    End Sub

    Private Sub dgfiles_ItemDataBound _
    (ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
    Handles dgfiles.ItemDataBound
    If e.Item.ItemType = ListItemType.Header Then
    e.Item.Cells(0).Text = "File Name"
    Exit Sub
    End If
    If e.Item.ItemType = ListItemType.AlternatingItem Or _
    e.Item.ItemType = ListItemType.Item Then
    Dim strFilename As String
    strFilename = System.IO.Path.GetFileName(e.Item.Cells(0).Text)
    e.Item.Cells(0).Text = strFilename
    End If
    End Sub


    <asp:datagrid id="dgfiles" runat="server"></asp:datagrid>



    "viktor9990" <> wrote in message
    news:...
    >I have a datagrid with 2 item templates inside a hyperlink and a label
    >(which
    > will show the file name and creation date of files which resides on a
    > folder
    > on the server. I'm using a procedure (GetScannedFiles()) to loop and get
    > the
    > required information from the folder but don't know how to show this info
    > inside my datagrid ( dynamically or from my aspx page). I appreciate any
    > help.
    > Look my code below.
    >
    > Here is the code for( MyDatagrid.aspx):
    >
    > <asp:datagrid id="DGFileScanned" runat="server"
    > Autogeneratecolumns="false" >
    > <Columns>
    >
    > <asp:TemplateColumn HeaderText="File Name">
    > <ItemTemplate>
    > <div>
    > <asp:hyperlink ForeColor="blue" Font-Size="10" id="FileName"
    > runat="server" >
    > .....
    > </asp:hyperlink></div>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > <asp:TemplateColumn>
    > <ItemTemplate>
    > <div>
    > <asp:Label ID="FileDate" Visible="true" Text="...." Runat="server" />
    > </div>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:datagrid>
    >
    > Here is the code behind for (Mydatagrid.aspx.vb)
    >
    > Private Sub GetScannedFiles()
    > 'Name of the folder which holds the scanned TIFF files (agreements
    > images)
    > Dim FolderPath As String =
    > Server.MapPath("/TrackerAggreement/admin/FilesTIFF/")
    > Dim source As DirectoryInfo = New DirectoryInfo(FolderPath)
    >
    > 'Get an array of all scanned TIFF files in the source direcotry
    > Dim sourceFiles As FileInfo() = source.GetFiles("*.tiff")
    > 'Loop to get File Names and Creation Time of the TIFF files in the
    > source direcotry
    > Dim i As Integer
    > For i = 0 To i < (sourceFiles.Length)
    > 'Get the File Name of every scanned TIFF file
    > Dim FileName As String =
    > Path.GetFileName(sourceFiles(i).FullName)
    > 'Get the Creation Time of every scanned TIFF file
    > Dim FileDate As String =
    > Path.GetFileName(sourceFiles(i).CreationTime)
    > i = i + 1
    > Next
    > End Sub
    Ken Cox [Microsoft MVP], Mar 30, 2005
    #4
  5. viktor9990

    Elton Wang Guest

    In addition from database, the DataTable can also be
    populated from other data source. Following code snippet
    shows how to fill datatable from a loop:

    DataTable myTable = new DataTable();
    Dim myColumn As DataColumn = New DataColumn
    myColumn.DataType = System.Type.GetType("System.String")
    myColumn.ColumnName = "FileName"
    myTable.Columns.Add(myColumn)
    myColumn New DataColumn
    myColumn.DataType = System.Type.GetType("System.String")
    myColumn.ColumnName = "FileDate"
    myTable.Columns.Add(myColumn)
    Dim row As DataRow
    For i As Integer = 0 To sourceFiles.Length - 1
    'Get the File Name of every scanned TIFF file
    Dim FileName As String = Path.GetFileName(sourceFiles
    (i).FullName)
    'Get the Creation Time of every scanned TIFF file
    Dim FileDate As String = Path.GetFileName(sourceFiles
    (i).CreationTime)
    ' filling data to datatable
    row = myTable.NewRow()
    row("FileName") = FileName
    row("FileDate") = FileDate
    myTable.Rows.Add(row)
    Next


    HTH

    Elton Wang

    >-----Original Message-----
    >In my solution I need to populate the datagrid without

    using the database. Is
    >there any solution?Thanks
    >
    >"Elton Wang" wrote:
    >
    >> You can use a datatable to save FileName and FileDate

    in
    >> it, and then bind the datagrid's data source with the
    >> datatable. In the datagrid you can use a

    HyperLinkColumn
    >> and a BoundColumn to show file name and file date.
    >>
    >> HTH
    >>
    >> Elton Wang
    >>
    >>
    >> >-----Original Message-----
    >> >I have a datagrid with 2 item templates inside a

    >> hyperlink and a label (which
    >> >will show the file name and creation date of files

    which
    >> resides on a folder
    >> >on the server. I'm using a procedure (GetScannedFiles

    ())
    >> to loop and get the
    >> >required information from the folder but don't know

    how
    >> to show this info
    >> >inside my datagrid ( dynamically or from my aspx

    page).
    >> I appreciate any
    >> >help.
    >> >Look my code below.
    >> >
    >> >Here is the code for( MyDatagrid.aspx):
    >> >
    >> ><asp:datagrid id="DGFileScanned" runat="server"

    >> Autogeneratecolumns="false" >
    >> ><Columns>
    >> >
    >> ><asp:TemplateColumn HeaderText="File Name">
    >> ><ItemTemplate>
    >> ><div>
    >> ><asp:hyperlink ForeColor="blue" Font-Size="10"

    >> id="FileName" runat="server" >
    >> > .....
    >> ></asp:hyperlink></div>
    >> ></ItemTemplate>
    >> ></asp:TemplateColumn>
    >> ><asp:TemplateColumn>
    >> ><ItemTemplate>
    >> ><div>
    >> ><asp:Label ID="FileDate" Visible="true" Text="...."

    >> Runat="server" />
    >> ></div>
    >> ></ItemTemplate>
    >> ></asp:TemplateColumn>
    >> ></Columns>
    >> ></asp:datagrid>
    >> >
    >> >Here is the code behind for (Mydatagrid.aspx.vb)
    >> >
    >> > Private Sub GetScannedFiles()
    >> > 'Name of the folder which holds the scanned

    TIFF
    >> files (agreements
    >> >images)
    >> > Dim FolderPath As String =
    >> >Server.MapPath("/TrackerAggreement/admin/FilesTIFF/")
    >> > Dim source As DirectoryInfo = New DirectoryInfo

    >> (FolderPath)
    >> >
    >> > 'Get an array of all scanned TIFF files in the

    >> source direcotry
    >> > Dim sourceFiles As FileInfo() = source.GetFiles

    >> ("*.tiff")
    >> > 'Loop to get File Names and Creation Time of

    the
    >> TIFF files in the
    >> >source direcotry
    >> > Dim i As Integer
    >> > For i = 0 To i < (sourceFiles.Length)
    >> > 'Get the File Name of every scanned TIFF

    file
    >> > Dim FileName As String = Path.GetFileName

    >> (sourceFiles(i).FullName)
    >> > 'Get the Creation Time of every scanned

    TIFF
    >> file
    >> > Dim FileDate As String =
    >> >Path.GetFileName(sourceFiles(i).CreationTime)
    >> > i = i + 1
    >> > Next
    >> > End Sub
    >> >.
    >> >

    >>

    >.
    >
    Elton Wang, Mar 30, 2005
    #5
  6. viktor9990

    viktor9990 Guest

    This has helped a lot but I still have difficulties in showing the embedded
    radio buttons and linking the filename(which is embedded too) which must be a
    link too in this datagrid. Thanks for further help.

    "Ken Cox [Microsoft MVP]" wrote:

    > Here's some code that populates a datagrid from file list. Perhaps it will
    > give you the idea?
    >
    > Ken
    > Microsoft MVP [ASP.NET]
    > Toronto
    >
    > Private Sub Page_Load _
    > (ByVal sender As System.Object, _
    > ByVal e As System.EventArgs) Handles MyBase.Load
    > 'create file list
    > Dim imagepath As String
    > imagepath = Server.MapPath("")
    > dgfiles.DataSource = _
    > System.IO.Directory.GetFiles(imagepath)
    > dgfiles.DataBind()
    >
    > End Sub
    >
    > Private Sub dgfiles_ItemDataBound _
    > (ByVal sender As Object, _
    > ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
    > Handles dgfiles.ItemDataBound
    > If e.Item.ItemType = ListItemType.Header Then
    > e.Item.Cells(0).Text = "File Name"
    > Exit Sub
    > End If
    > If e.Item.ItemType = ListItemType.AlternatingItem Or _
    > e.Item.ItemType = ListItemType.Item Then
    > Dim strFilename As String
    > strFilename = System.IO.Path.GetFileName(e.Item.Cells(0).Text)
    > e.Item.Cells(0).Text = strFilename
    > End If
    > End Sub
    >
    >
    > <asp:datagrid id="dgfiles" runat="server"></asp:datagrid>
    >
    >
    >
    > "viktor9990" <> wrote in message
    > news:...
    > >I have a datagrid with 2 item templates inside a hyperlink and a label
    > >(which
    > > will show the file name and creation date of files which resides on a
    > > folder
    > > on the server. I'm using a procedure (GetScannedFiles()) to loop and get
    > > the
    > > required information from the folder but don't know how to show this info
    > > inside my datagrid ( dynamically or from my aspx page). I appreciate any
    > > help.
    > > Look my code below.
    > >
    > > Here is the code for( MyDatagrid.aspx):
    > >
    > > <asp:datagrid id="DGFileScanned" runat="server"
    > > Autogeneratecolumns="false" >
    > > <Columns>
    > >
    > > <asp:TemplateColumn HeaderText="File Name">
    > > <ItemTemplate>
    > > <div>
    > > <asp:hyperlink ForeColor="blue" Font-Size="10" id="FileName"
    > > runat="server" >
    > > .....
    > > </asp:hyperlink></div>
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > > <asp:TemplateColumn>
    > > <ItemTemplate>
    > > <div>
    > > <asp:Label ID="FileDate" Visible="true" Text="...." Runat="server" />
    > > </div>
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > > </Columns>
    > > </asp:datagrid>
    > >
    > > Here is the code behind for (Mydatagrid.aspx.vb)
    > >
    > > Private Sub GetScannedFiles()
    > > 'Name of the folder which holds the scanned TIFF files (agreements
    > > images)
    > > Dim FolderPath As String =
    > > Server.MapPath("/TrackerAggreement/admin/FilesTIFF/")
    > > Dim source As DirectoryInfo = New DirectoryInfo(FolderPath)
    > >
    > > 'Get an array of all scanned TIFF files in the source direcotry
    > > Dim sourceFiles As FileInfo() = source.GetFiles("*.tiff")
    > > 'Loop to get File Names and Creation Time of the TIFF files in the
    > > source direcotry
    > > Dim i As Integer
    > > For i = 0 To i < (sourceFiles.Length)
    > > 'Get the File Name of every scanned TIFF file
    > > Dim FileName As String =
    > > Path.GetFileName(sourceFiles(i).FullName)
    > > 'Get the Creation Time of every scanned TIFF file
    > > Dim FileDate As String =
    > > Path.GetFileName(sourceFiles(i).CreationTime)
    > > i = i + 1
    > > Next
    > > End Sub

    >
    >
    viktor9990, Mar 30, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    1
    Views:
    375
  2. Paul

    Timeout on populating a datagrid

    Paul, May 5, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    2,880
    Scott Allen
    May 5, 2004
  3. =?Utf-8?B?VGltOjouLg==?=

    Datagrid Dropdown not populating

    =?Utf-8?B?VGltOjouLg==?=, Aug 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    372
  4. Prime
    Replies:
    2
    Views:
    1,629
    Prime
    Oct 1, 2004
  5. Bob Hollness

    Populating a DataGrid

    Bob Hollness, Jan 12, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,482
    =?Utf-8?B?c2FyYQ==?=
    Jan 12, 2005
Loading...

Share This Page