Forum Moderators: open

Message Too Old, No Replies

value from outside database insede datalist!

         

makeit

12:49 am on Feb 14, 2005 (gmt 0)

10+ Year Member



I am really discourage!
For the last 2 weeks(ya might think i'm stupid) I have been trying to insert a label inside a datalist and just can't do it.(sound so simple)

<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.

Jimmy Turnip

4:20 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



Put the stream reader in a function like so:


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")) %>

makeit

12:10 am on Feb 15, 2005 (gmt 0)

10+ Year Member



jimmy turnip your idea seems so good! the only problem is that i don't have a column name "pathfromdatabase" and when I try to run the progra the computer let's me know that!

DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name pathfromdatabase.

but i feel like I'm getting closer!
thanx

makeit

1:14 am on Feb 15, 2005 (gmt 0)

10+ Year Member



jimmy turnip millions of thanks!it works
<%# GetMessageText(DataBinder.Eval(Container.DataItem, "columnfrommydatabase")) %>