c# - Change directory path of GridView -
i have website , on 1 of pages have several gridviews
. have requirement each gridview
show different files different directory. can files , view them in gridview
can't seem figure out how go changing directory path each grid. have far
public class filedetails { public string filename { get; set; } public string fullpath { get; set; } } string[] filepaths = directory.getfiles(server.mappath("~/document/generic/")); list<filedetails> files = new list<filedetails>(); foreach(string filepath in filepaths) { string filename = path.getfilenamewithoutextension(filepath); files.add(new filedetails() { filename = filename, fullpath = filepath, }); } gridview1.datasource = files; gridview1.databind();
how implement above code change directory path gridview2, gridview3 , gridview4
.
thanks in advance , support
you can create method accepts string argument directory name , returns gridview thing below :
public gridview bindmygrid(string directoryname) { // declare gridview grd = new gridview() //fetch files directory //set grd.datasource //return grd }
and can call method set different grids as
gridview grid1 = bindmygrid("directory1") gridview grid2 = bindmygrid("directory2") gridview grid3 = bindmygrid("directory3")
Comments
Post a Comment