asp.net - Adding link dynamically to Template Field -
i need replace link each data bound item. checked out databound event of datarow. problem can't control link shows up. i'm trying stay away javascript , keep in code behind. below asp code , code behind have. want try keep same possible, not changing html template items. process im using follows.
i have custom object contains fields , data of blog entry. items put list , supplied datagrid.
<asp:gridview id="grdrecentnews" runat="server" autogeneratecolumns="false" datakeynames="key" gridlines="none" pagesize="4" showheader="false" allowpaging="true"> <pagersettings visible="false" /> <columns> <asp:templatefield> <itemtemplate> <blockquote> <%-- <strong><a href=**"news.aspx"**>--%> <strong><a href="news.aspx"> <%#eval("newsdesc")%></a></strong> <br /> <span class="italic"> <%#eval("newsdate")%></span> </blockquote> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
this code had in databound event, problem being want provide link 1 of fields of rss object. above below. want replace news.aspx" each item added datagrid rssobject's link property.
protected sub grdrecentnews_rowdatabound(byval sender object, byval e system.web.ui.webcontrols.gridviewroweventargs) handles grdrecentnews.rowdatabound if e.row.dataitem isnot nothing andalso e.row.dataitem.tostring = "rssentry" dim curitem rssentry = ctype(e.row.dataitem, rssentry) e.row.attributes.add("href", curitem.link) 'data-url end if end sub
i found way insert <%#eval %> statement attribute wanted change. point towards correct property of rssobject, , working.
<columns> <asp:templatefield> <itemtemplate> <blockquote> <strong><a href='<%#eval("link")%>'> <%#eval("newsdesc")%></a></strong> <br /> <span class="italic"> <%#eval("newsdate")%></span> </blockquote> </itemtemplate> </asp:templatefield> </columns>
Comments
Post a Comment