where i am wrong
-
I have a hyperlink control code that need to bind from a database. However, I am still not very familiar with this. Can somebody help me? And may you tell me the rules about bind data to html code? The italic part is the wrong code.... <asp:HyperLink NavigateUrl='index?titlename='<%# container.dataitem("title") %> Runat ="server" ><%# container.dataitem("title") %></asp:HyperLink>
-
I have a hyperlink control code that need to bind from a database. However, I am still not very familiar with this. Can somebody help me? And may you tell me the rules about bind data to html code? The italic part is the wrong code.... <asp:HyperLink NavigateUrl='index?titlename='<%# container.dataitem("title") %> Runat ="server" ><%# container.dataitem("title") %></asp:HyperLink>
Hi there. Do a Google search for "DataBinding Syntax". There are lots of articles on this topic. I can see two possible problems with the code - the single quote delimiters should include the databinding too, and you may need to either cast the
Container.DataItem
object or useDataBinder.Eval
. If your datasource is aDataTable
for example, you can cast the object as aDataRowView
. C#NavigateUrl='index?titlename=<%#((DataRowView)Container.DataItem)["title"] %>'
In VB:
NavigateUrl='index?titlename=<%# CType(Container.DataItem, DataRowView)("title") %>'
DataBinder.Eval syntax would look like this:
NavigateUrl='index?titlename=<%# DataBinder.Eval(Container.DataItem, "title") %>'