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
  • 214,658
  • 40
  • 293
  • 332
Steven Zack
  • 4,714
  • 19
  • 56
  • 86

2 Answers2

2
<div id="test<%=Eval("id")%>"></div>
Will Stern
  • 16,513
  • 5
  • 34
  • 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,692
  • 1
  • 14
  • 24