Bind to a hyperlinkfield in a gridview

I have a gridview which pulls data from an xml file. One of the columns of the gridview is a hyperlinkfield. I want to bind a URL field contained in my XML file to this column. I think I have the right idea with the code below but cant figure out how to finish it. The URL is the datakey of the gridview by the way.

protected void grdContents_RowCreated(object sender, GridViewRowEventArgs e)
{
    ((HyperLinkField)grdContents.Columns[1]).NavigateUrl = 






}

Answers


you can bind hyperlink on gridView_RowDataBound event like this

    protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType.Equals(DataControlRowType.DataRow))
            {
                HyperLinkField lnkHyper = (HyperLinkField)e.Row.FindControl("HyperLinkField1");
                lnkHyper.NavigateUrl="";
            }
        }

try this.

or you can also bind url using DataBinder.Eval at the time of binding source to grid like

 <Columns>
       <asp:TemplateField>                                           
        <ItemTemplate>
             <asp:HyperLink runat="server" 
NavigateUrl="<%# DataBinder.Eval(Container.DataItem, "url") %>"></asp:HyperLink>
         </ItemTemplate>
        </asp:TemplateField>
</Columns>

You can use this as well, as you also providing data source to Grid view.


Need Your Help

Create CGImageRef without caching anything

cocoa caching nsdata quartz-graphics core-services

I need to create thousands of CGImage objects using CGImageSourceCreateThumbnailAtIndex(...).

JOGL error with glVertexAttribPointer

java opengl jogl vao

I am tring the code below (using VAO(Vertex Buffer Object) and glDrawArraysInstanced method)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.