ASP.NET and database question

  • Thread starter Thread starter yossimotro
  • Start date Start date
Y

yossimotro

Hi,

I've been using asp.net's Repeater and SqlDataSource tools to display
data from a database.
One of the fields contains a number which represents the number of
images i need to display.
What I was trying to do is to write a function that will receive this
number and add %number% image tags.

When I try to pass the field to the function using Eval("field") I get
an error and I've been looking all over the net how to actually use
data from the database rather than just display it.

Anyone has any ideas?

Thanks,
Yossi.
 
When I try to pass the field to the function using Eval("field") I get
an error and I've been looking all over the net how to actually use
data from the database rather than just display it.

Hint: When the sytsem gives you an error, posting that error will likely
give you more responses. Otherwise, people will pass you over because your
question is too general.
 
Hello,
if you are trying to display an image rather than a text field
according to your database value,
you should use a template field, catch the itemdatabound event of your
repeater and change your image's url in that event handling function.

The following code snippets may be useful...
in aspx file

<asp:Repeater ID="Repeater1" runat="server"
OnItemDataBound="repeater1_OnItemDataBound">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="navbar">
<asp:PlaceHolder ID="indentPlace"
runat="server"></asp:PlaceHolder>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

protected void repeater1_OnItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.Item.ItemIndex < count)
{
PlaceHolder placeHolder =
(PlaceHolder)e.Item.FindControl("indentPlace");
Image imgIndent = new Image();
imgIndent.ImageUrl = "../images/indentImage" +
e.Item.ItemIndex + ".gif";
HyperLink icerikLink = new HyperLink();
TreeStructure ts = (TreeStructure)e.Item.DataItem;
icerikLink.NavigateUrl = "..someurl=" +
ts.TagObject.Id;
icerikLink.Text = ts.TagText;
placeHolder.Controls.Add(imgIndent);
placeHolder.Controls.Add(icerikLink);
}
}
}
 
Yossi,

You need to handle the repeater's ItemDataBound event in the code-behind.
The event handler gets a reference to each item being bound. You can get the
value of the Number column and add the tags. Everything in the same event
handler in your favorite dotnet language.

Eliyahu
 
Hi,

First of all, Thanks for all your responses.
But Isn't there any simple way of sending data from the repeater to a
function as a parameter?

Thanks again,
Yossi.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top