Click here to Skip to main content
15,886,056 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i uploaded file in gridview and now i want to view these files i.e when any user click view button then this documnet view in broswer or open in other tab




ASP.NET
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
        GridLines="None" AutoGenerateColumns="false" EmptyDataText="no files uploaded">
     
        <asp:HyperLink  runat="server" ID="lnkButton" Text="View File" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#999999" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>



C#
<pre lang="cs">protected void FileUpload_Click(object sender, EventArgs e)
     {
         if (FileUploadControl.HasFile)
         {
             string strPath = Request.PhysicalApplicationPath + &quot;~/DocFiles/&quot; + FileUploadControl.FileName;
             FileUploadControl.SaveAs(strPath);
             lnkButton.NavigateUrl = &quot;~/DocFiles/&quot; + FileUploadControl.FileName;
         }
     }



but i find the error in link button

"The name 'lnkButton' does not exist in the current context "

where as i call the link button in grdiview (gridvie code above)

any help plzzz
Posted
Updated 23-Sep-13 6:23am
v3

1 solution

You can do something like this:
foreach(GridViewRow row in GridView1.Rows)
{
 LinkButton lb = (LinkButton) row.Cells[1].FindControl("id of button"); // Just change the index of Cells based on your requirements

} 


This info was provided by this article:
Click
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900