the real value of the combo box

T

Tan

Hello Everyone
Need help!

I have a object with the integer property that represent the address type. I
like to show a combo box in the grid linked to an object data source
displaying the string value instead of integer value.

any help would very much appriciated

Tan
 
L

Lars Netzel

???

Very little to go on here but ok.. please add code to these kind of
questions.

If you are infact binding the DropDownbox from a datasource.. then just set
the DateValueField to the name of that field in the datasource.

But since you are using the word "ComboBox".. are you using ASP or Windows
Forms (This is the ASP.NET forum you know... so the question might be in
the wrong place)?

/Lars
 
T

Tan

I am developing a asp.net program and I want to display a dropdown box in
the details view linked to object data source

But I do not know how to display a dropdown box in thie Details view showing
the string value instead of integer

thank a lot

Tan
 
L

Lars Netzel

Okay, so you have a DropDownBox in a Column of a DataGrid then?

A DropDown box is always a DropDownBox with all the same Properties and
Methods.
If it is in a DataGrid the only thing that differes is that its named
dynamically and you will have to add some more code to access the right
DropDownBox just... A Good place to access the right box is in the
DataItemBound event of the DataGrid.

But you still have the DataTextField and the DataValueField to use ...

If it seems like I'm not really getting what you are asking then please
provide more detailed information abtou this.

Best Regards/
Lars Netzel
 
M

Mona

Hi Tan,

A dropdown box holds a list of "ListItem" objects... each listitem object
has a piece of text that it shows,
and a piece that is its corresponding "value" so you're adding the text and
value to the listitem object,
then adding it to the dropdown box.

In a loop, you can do the following:

DropDownList1.Items.Add(New ListItem(yourobject.textvalue,
yourobject.integervalue))
for each object's text and corresponding value

HTH

Mona[Grapecity]
 
D

Diego

I think I've understood he need to use a template column with a DropDownBox,
but I dont' how to link the ddb with the field so I let you suggest ;).
Bye, Diego
 
L

Lars Netzel

Well since controls within a datagrid do not exists until runtime you will
have to access and set the datasource in runtime in the right even and the
right event here would be "ItemDataBound" of the Datagrid. here's an
example:

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

'Get a referense to the object

Dim drpMyDropList As DropDownList =
CType(e.Item.FindControl("DropDownList1"), DropDownList)

'Set the right things to be able to bind

drpMyDropList.DataTextField = "..."

drpMyDropList.DataValueField = "..."

drpMyDropList.DataSource = 'some object

drpMyDropList.DataBind()

End Sub

Best Regards/

Lars Netzel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top