none
How to change text field of a hyperlink RRS feed

  • Question

  • In my page there is a fileupload control and a gridview. When I upload a file, the DocName and the path of the saved file will in the gridview. I put the filepath in a hyperlink field so that it will show "View file"(not the path). My problem is -
                    the gridview is showing "view file" text when there is no file saved.
    It works fine when I upload a file.
    GridView :

    <

     

    asp:GridView ID="gvFile" runat="server" AllowPaging="True" AutoGenerateColumns="False"

     

    DataSourceID="odsrcInsertUpload" Width="552px" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">

     

    <Columns>

     

    <asp:TemplateField HeaderText="Doc. Name" SortExpression="DocName">

     

    <EditItemTemplate>

     

    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("DocName") %>'></asp:TextBox>

     

    </EditItemTemplate>

     

    <ItemTemplate>

     

    <asp:Label ID="lblDocName" runat="server" Text='<%# Bind("DocName") %>'></asp:Label>

     

    </ItemTemplate>

     

    </asp:TemplateField>

     

    <asp:TemplateField HeaderText="DocLink" SortExpression="DocLink" Visible="False">

     

    <EditItemTemplate>

     

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DocLink") %>'></asp:TextBox>

     

    </EditItemTemplate>

     

    <ItemTemplate>

     

    <asp:Label ID="lblDocLink" runat="server" Text='<%# Bind("DocLink") %>'></asp:Label>

     

    </ItemTemplate>

     

    </asp:TemplateField>

     

    <asp:TemplateField HeaderText="View File">

     

    <ItemTemplate>

     

    <asp:HyperLink ID="hlViewFile" runat="server" NavigateUrl='<%# Eval("DocLink") %>'

     

    Text="View File" Target="_blank" Height="16px" Width="72px"></asp:HyperLink>

     

    </ItemTemplate>

     

    </asp:TemplateField>

     

    </Columns>

     

    <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />

     

    <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />

     

    <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />

     

    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />

     

    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />

     

    <AlternatingRowStyle BackColor="#F7F7F7" />

     

    </asp:GridView>

    I tried with this code in the Code file:(vb)

    Protected

     

    Sub gvFile_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvFile.PreRender

    gvFile.EmptyDataText =

    "No file uploaded"

     

    End Sub

    Please help!
    Thanks,

    Wednesday, October 21, 2009 4:38 PM

Answers

  • Your HTML isn't relevant to your question.  What you need to do here is go into your CodeBehind file and instantiate the hyperlink itself (either by pulling it from the referenced ASP WebForm or by creating it programmatically and adding it to the ASP WebForm from the start).

    At that point, you modify the object in memory and make sure that whenever the page posts back the new hyperlink object data is passed to the ASP WebForm before it's returned to the user.
    It never hurts to try. In a worst case scenario, you'll learn from it.
    • Marked as answer by Jeff Shan Monday, October 26, 2009 6:43 AM
    Wednesday, October 21, 2009 4:58 PM
  • This forum is not for web form questions it is for Windows.Forms and VB.net . For questions about ASP and the VB codebehind try the ASP forum http://forums.asp.net
    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    • Marked as answer by Jeff Shan Monday, October 26, 2009 6:43 AM
    Wednesday, October 21, 2009 8:43 PM

All replies

  • Your HTML isn't relevant to your question.  What you need to do here is go into your CodeBehind file and instantiate the hyperlink itself (either by pulling it from the referenced ASP WebForm or by creating it programmatically and adding it to the ASP WebForm from the start).

    At that point, you modify the object in memory and make sure that whenever the page posts back the new hyperlink object data is passed to the ASP WebForm before it's returned to the user.
    It never hurts to try. In a worst case scenario, you'll learn from it.
    • Marked as answer by Jeff Shan Monday, October 26, 2009 6:43 AM
    Wednesday, October 21, 2009 4:58 PM
  • This forum is not for web form questions it is for Windows.Forms and VB.net . For questions about ASP and the VB codebehind try the ASP forum http://forums.asp.net
    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
    • Marked as answer by Jeff Shan Monday, October 26, 2009 6:43 AM
    Wednesday, October 21, 2009 8:43 PM