-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: sorting problem Datagrid
PostPosted: Tue Nov 22, 2005 1:43 pm 
Newbie

Joined: Wed Nov 02, 2005 9:52 am
Posts: 18
Location: Argentina
Hi i'm again
the problem is as follows:
I have a datagrid (asp.net) wich list users, users have a UserType, i can order the datagrid by any property of User class, except for the propertis linked with other tables

TipoUsuario.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Business.Data.TipoUsuario,Business" table="TipoUsuario">
   <id name="IdTipoUsuario" column="idTipoUsuario" type="Int32" unsaved-value="0">
  <generator class="native" />
  </id>
   <bag name="UsuarioList" inverse="true" lazy="true">
   <key column="idTipoUsuario" />
   <one-to-many class="Business.Data.Usuario,Business" />
  </bag>
  <property column="tipoUsuario" type="String" name="nTipoUsuario" not-null="true" length="50" />
  <property column="baja" type="Boolean" name="Baja" not-null="true" />
  </class>
</hibernate-mapping>


Usuario.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="Business.Data.Usuario,Business" table="Usuario">
   <id name="IdUsuario" column="idUsuario" type="Int32" unsaved-value="0">
  <generator class="native" />
  </id>
  <property column="apellido" type="String" name="Apellido" length="50" />
  <property column="nombre" type="String" name="Nombre" length="50" />
  <property column="usuario" type="String" name="nUsuario" not-null="true" length="50" />
  <property column="pass" type="String" name="Pass" not-null="true" length="50" />
  <property column="mail" type="String" name="Mail" not-null="true" length="50" />
  <many-to-one name="IdTipoUsuario" column="idTipoUsuario" class="Business.Data.TipoUsuario,Business" />
  <property column="baja" type="Boolean" name="Baja" not-null="true" />
  </class>
</hibernate-mapping>


the Datagrid html code
Code:
<asp:TemplateColumn SortExpression="nUsuario" HeaderText="Usuario">
<ItemTemplate>
   <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "nUsuario") %>' />
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn SortExpression="idTipoUsuario" HeaderText="TipoUsuario">
<ItemTemplate>
   <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "idTipoUsuario.nTipoUsuario") %>' />
</ItemTemplate>
</asp:TemplateColumn>


The problem is when sorting by idTipoUsuario in the second TemplateColumn coz idTipoUsuario refers to an object so then I change this for "idTipoUsuario.nTipoUsuario" but nothing the Datagrid can't find the property "idTipoUsuario.nTipoUsuario" in the TipoUsuario column.

It's possible use sorting in this way? how ?

i'm so tried putting the SortExpression like this
SortExpression="<%# DataBinder.Eval(Container.DataItem, "idTipoUsuario.nTipoUsuario") %>"
but fails too.

In this case i must use the common (System.Data ) bindigs for the grid? or convert the NHibernate objects to datatable and use this ?

Somebody with a torch?

Thanks in advance!

Antares


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 10:26 am 
Beginner
Beginner

Joined: Mon Oct 03, 2005 4:59 am
Posts: 26
Location: Cambridge, UK
Wild guess:
SortExpression="((Business.Data.TipoUsuario) idTipoUsuario).nTipoUsuario"

Or maybe, since (I think) sorting a datagrid requires a server round trip anyway, you might think about storing your list in the HttpSession and when the user wants to sort the datagrid, just pull it out again, sort it manually, and databind again. Ugly, but perhaps less so than building a datatable.

Just some ideas; (obviously) I've never tried to do this.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 10:49 am 
Newbie

Joined: Wed Nov 02, 2005 9:52 am
Posts: 18
Location: Argentina
Thanks, im using now a Query for get the data (before a Criteria) and in the qry explicitly tell wich data i need, some thing like this:

Code:
select op.id , op.nOperadora, op.IdBase.nVase from Operadora op
where op.IdBase.id=:clave order by op.nOperadora desc


Sorry by the example but is the one im working now

and those get the data in a plain "table"

off-topic:
it's possible use the AS for column aliases in HQL?
like this:
Code:
select op.id AS idOperadora, op.nOperadora, op.IdBase.nVase AS nVase from Operadora op
where op.IdBase.id=:clave order by op.nOperadora desc


Tkz :lol:
Antares


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 5:31 pm 
Newbie

Joined: Wed Nov 02, 2005 9:52 am
Posts: 18
Location: Argentina
Finally i coud solve the problem using an HQL query like the first one from above post -^

Now i'm trying to put all in a MyGeneration
template for automate generation of datagrids :)


Tks All

Antares

PD: in MyGeneration you can find templates for creation of .hbm.xml & class files for NHibernate and are FREE !!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.