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.  [ 3 posts ] 
Author Message
 Post subject: How to insert one column in table to dropdownlist
PostPosted: Tue Jan 29, 2008 1:14 pm 
Newbie

Joined: Sun Jan 27, 2008 4:26 pm
Posts: 18
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

i am using a dropdown list in asp.net.How could i insert one column data
in table to dropdownlist using NHibernate.
I am not getting any error but i just could not insert any data in to dropdownlist.

Hibernate version:
NHibernate 1.2.1 GA

Mapping documents:
DVBStatus Mapping
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="FreeView" assembly="FreeView">
<class name="DVBStatus" table="DVBStatus" lazy="false" mutable="true">
<id name="DVBStatusID" column="DVBStatusID" type="int">
<generator class="increment"></generator>
</id>
<set name="DVBChannel" table="DVBChannel" cascade="all" inverse="true">
<key column="DVBStatusID" />
<one-to-many class="DVBChannel" />
</set>
<property name="Description" column="Description" type="string"/>
</class>
<query name="DVBStatus">from DVBStatus</query>

</hibernate-mapping>

DVBChannel Mapping
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="FreeView" assembly="FreeView" default-access="property">
<class name="DVBChannel" lazy="false" table="DVBChannel" >
<id name="DVBChannelID" column="DVBChannelID" type="int">
<generator class="native"></generator>
</id>
<property name="DVBChannelNo" column="DVBChannelNo" type="int"/>
<property name="DVBChannelName" column="DVBChannelName" type="string"/>
<property name="DVBChannelURL" column="DVBChannelURL" type="string"/>
<many-to-one name="DVBStatus" class="DVBStatus" column="DVBStatusID" cascade="none" not-null="true" fetch="select"/>
<property name="EPGDataFile" column="EPGDataFile" type="string"/>
<property name="Description" column="Description" type="string"/>
</class>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
public void LoadControls(Control source)
{
DropDownList x_DVBStatusID = ((DropDownList)source.FindControl("x_DVBStatusID"));
NHibernate.ISessionFactory factory=Persister.getFactory;
using(NHibernate.ISession session=factory.OpenSession())
using(session.BeginTransaction())
{
DVBStatus status=new DVBStatus();
IList dvbStatus = session.CreateCriteria(typeof(DVBStatus)).List();
x_DVBStatusID.DataValueField = Convert.ToString(status.DVBStatusID);
x_DVBStatusID.DataTextField=status.Description;
x_DVBStatusID.DataSource = dvbStatus;
x_DVBStatusID.DataBind();
x_DVBStatusID.Items.Insert(0, new ListItem("Please Select", ""));
}

}

Full stack trace of any exception that occurs:

Name and version of the database you are using:
sqlserver 2005

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 3:26 pm 
Newbie

Joined: Fri Dec 14, 2007 3:20 pm
Posts: 8
Not sure with native .net dropdown (I'm using a 3rd party control) but you might be able to bind to an IList.

If not, why can't you just create a method that loops through the resultant IList and put the description into the combo?

Something like:

For each Status as DVBStatus in Results
combobox1.add(status.DVBChannelNo, status.DVBChannelName)
next

Assuming that DVBChannelNo is the value you want associated with the text of ChannelName


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 3:41 pm 
Newbie

Joined: Tue Jan 22, 2008 5:51 pm
Posts: 7
Location: Brazil
first of all, try use those properties like this:
(i do not have sure! but!)

Code:

x_DVBStatusID.DataValueField = "DVBStatusID";
x_DVBStatusID.DataTextField= "Description";
x_DVBStatusID.DataSource = dvbStatus;
x_DVBStatusID.DataBind();
x_DVBStatusID.Items.Insert(0, new ListItem("Please Select", ""));




if even u tried and doesn't work, try convert your (NonGenericList) IList to a (GenericList) List<ObjectType>

maybe it works together !

cya!!

good luck!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.