Assigning variable to Repeater value
I'm very new to .NET and this is driving absolutely crazy. I want to pull a value from my database and then assign it to a variable that I can pass into javascript. Printing the value is easy, but does nothing for me!
<asp:Repeater ID="Repeater3" runat="server" DataSourceID="SqlDataSource11">
<ItemTemplate>
<asp:BoundField DataField="videofile" />
<%#DataBinder.Eval(Container.DataItem, "videofile")%>
<%=vidfile%>
</ItemTemplate>
vid开发者_开发百科eofile is the variable from the database, and vidfile is the variable I want to assign it to. I also tried this <%# vidfile = DataBinder.Eval(Container.DataItem, "videofile")%>
and that gave me the output of 'False'.
help!
Keep in mind that if your variable "vidfile" is declared in javascript, the server has no idea what that is.
Anything executing inside of ASP tags is strictly in the context of the server. If you'd like to assign a string to a variable, you want to get the server to print something directly into the rendered page.
Also keep in mind that the ASP tag <%= %>
is a shortcut for "Response.Write()", which will render a string into the outputted page. The <%# %> syntax is for use when binding a control's property to a datasource, or utilizing the databinder methods.
Something like this might work for you:
<asp:Repeater ID="Repeater3" runat="server" DataSourceID="SqlDataSource11">
<ItemTemplate>
<asp:BoundField DataField="videofile" />
<script language="text/javascript">
vidfile = '<%# DataBinder.Eval(Container.DataItem, "videofile", "{0}") %>'
</script>
</ItemTemplate>
精彩评论