Suppose,we have datagrid,and we have also some files which we want to show on datagrid,then we will write below code as:-
<asp:DataGrid runat = "server" Id = "grid_files" AutoGenerateColumns = "False">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name" HeaderText="File Name"></asp:HyperLinkColumn>
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time" DataFormatString="{0:d}"></asp:BoundColumn>
<asp:BoundColumn DataField="Length" HeaderText="File Size" DataFormatString="{0:#,### bytes}"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
'VB/Net
Dim dirInfo As New DirectoryInfo(Server.MapPath(""))
grid_files.DataSource = dirInfo.GetFiles("*.aspx")
grid_files.DataBind()
//C#
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(""));
grid_files.DataSource = dirInfo.GetFiles("*.aspx");
grid_files.DataBind();