Quantcast
Channel: CodeProject Latest postings for ASP.NET
Viewing all articles
Browse latest Browse all 3938

Gridviews and hyperlinks help please

$
0
0
Hey Guys
i have to create a webpage that has a button and gridview, once the button is pressed it triggers the click button method which searches my computer for files in a specific folder once files are found it displays it in the grid view .
which i have managed to do my problem is im expected to then give the ability that if the user clicks on the file name(which is a hyperlink) in the grid view that it opens on a new page and that the file is embed in that page ready for viewing??
 
i have tried all i can think off.
 
ps the files not in a db they in a folder on my pc later will be on a sever in a folder
 
hope some on can help me
 
here is what i have so far
<formid="form1"runat="server"><asp:ButtonID="Button1"runat="server"Text="Button"OnClick="Button1_Click"/><asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"Width="119px"><Columns><asp:TemplateFieldHeaderText="FileName"><ItemTemplate><asp:HyperLinkID="HyperLink1"runat="server"NavigateUrl='<%# Eval("Dir","~/Dir={0}")%>'Text='<%# Eval("File") %>'PostBackUrl="/WebForms4.aspx"></asp:HyperLink></ItemTemplate></asp:TemplateField><asp:BoundFieldDataField="size"HeaderText="size"/><asp:TemplateFieldHeaderText="diretory"><ItemTemplate><asp:ButtonID="Button2"runat="server"CommandArgument='<%# Eval("Dir","~/WebForms4.aspx/files?Dir={0}") %>'Text='<%# Eval("Dir") %>'PostBackUrl="~/WebForms4.aspx?Dir={0}"/></ItemTemplate></asp:TemplateField></Columns></asp:GridView>
 
and C# code
protectedvoid Button1_Click(object sender, EventArgs e)
        {
            DataTable Dt = new DataTable();
            Dt.Columns.Add("File", typeof(string));
            Dt.Columns.Add("Size", typeof(string));
            Dt.Columns.Add("Dir", typeof(string));
            foreach (string filename in Directory.GetFiles(@"C:\files"))
            {
                FileInfo fileinfo = new FileInfo(filename);
                Dt.Rows.Add(fileinfo.Name, fileinfo.Length +"KB", fileinfo.FullName);
 
                
            }
            GridView1.DataSource = Dt;
            GridView1.DataBind();
        }
 

Thanks in advancedThumbs Up | :thumbsup:

Viewing all articles
Browse latest Browse all 3938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>