Forum Moderators: open
<asp:DataList id="DataList1" runat="server" RepeatColumns="2" OnItemDataBound="Item_Bound">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "fromdatabase") %> 'value from the database
<asp:Label runat="server" id=" lblMessage" />' value from a file
</ItemTemplate>
</asp:DataList>
I want to diplay a text that will come from a file with the (lblMessagetxt.txt) this text is not in the database(only the path of the text is) ."fromdatabase" is from my database.
if I put the <asp:Label runat="server" id="lblMessagetxt" /> outside the<asp:DataList it works just fine when I put it inside, the program can not see the label in the html section.
dim fs as new FileStream(Server.MapPath _
(textfilepath), FileMode.Open, FileAccess.Read)
dim objReader as new StreamReader(fs)
lblMessage.Text = "<DIV ALIGN=right>"
while objReader.Peek() > -1
lblMessage.Text += Server.HTMLEncode _
(objReader.ReadLine) & "<br>"
end while
objReader.Close
fs.close
I always get --> Name 'lblMessage' is not declared. and the label is there in the html section
if I put the asp:label outside the datalist it works just fine.
the problem to sum this whole thing up is that I can't integrat insite the datalist a varialbe that is not from my database.
thanks in advance.
Public Function GetMessageText(ByVal MessagePath As String) As String
dim fs as new FileStream(Server.MapPath _
(MessagePath), FileMode.Open, FileAccess.Read)
dim objReader as new StreamReader(fs)
GetMessageText = "<DIV ALIGN=right>"
while objReader.Peek() > -1
GetMessageText += Server.HTMLEncode _
(objReader.ReadLine) & "<br>"
end while
objReader.Close
fs.close
End Function
Then remove the label from the datalist and replace with:
<%# GetMessageText(DataBinder.Eval(Container.DataItem, "pathfromdatabase")) %>
DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name pathfromdatabase.
but i feel like I'm getting closer!
thanx