0

I'm wondering how to get a combination name like "test1" by using <%# Eval("id") %>

I want to name a div by the id field from a datatable, I can get the id in frontend by using <%# Eval("id") %>, I want the div name to be something like test1, test2.

Is this right?

<div id="<%# test+Eval("id") %>"></div>

This code is supposed to write in frontend page of an asp.net website project.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Steven Zack
  • 4,984
  • 19
  • 57
  • 88

2 Answers2

2
<div id="test<%=Eval("id")%>"></div>
Will Stern
  • 17,181
  • 5
  • 36
  • 22
0

If the div is in a databound control use:

 <div id='<%# "test"+Eval("id") %>'></div> 

Eval() method works only in a databound control

Single-Value Databinding
or if the id is a protected/public variable

 <div id="<%# "test"+id %>"></div>

or even call your own method (protected/public)

<div id= "<%# "test"+Counter() %>"></div>

Then in the page load event call this method

 DataBind()
Mubarek
  • 2,691
  • 1
  • 15
  • 24