简体   繁体   中英

asp.net Make a listView row clickable without a button

I want to make a listview row clickable without using a button. the listview is filled with data out of a database so putting a onclick methode directly on the tr isnt a option.

I found this tread: http://forums.asp.net/t/1419161.aspx

But i get the error: " registerforeventvalidation can only be called during render()" at line:

     string script = this.ClientScript.GetPostBackClientHyperlink(btn, "", true);

This is fixable by setting " enableEventValidation="false" " at @Page directive.

Now my question:

  • Am i doing something wrong?
  • is it a bad thing to do to turn eventValidation off?
  • is there a better way of doing this? if so how?

i prefer listview but if there is a better way that involves some other grid like control i would also like to hear that.

i am making this in asp.net VB.net but c# example is also fine.

Thanks!

You can do this from a database. In the example below clicking on the row will call a javascript function called evalItem, and pass the "Publisher" field from the data item for the row bound to the listview.

 <ItemTemplate>
    <tr class="clsGroupRowSelectable" onclick='evalItem(&#39;<%# Eval("Publisher").ToString() %>&#39;);'>
       <td><%# Eval("Number") %>' /></td>
    </tr>
 </ItemTemplate>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM