Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I have a drop-down list that is databound to a dataset. For the sake of this question the fields in the dataset are Field1, Field2, Field3 and Field4.

 

In the Properties for the DDL I have previously set the the following values:

 

DataTextField = Field1

DataValueField = Field4

 

Now I want to display in the Text of the DDL the following:

 

Field2 - Field3, Field4

 

I understand that I can do this type of formatting in the DataTextFormatField but I can only get it to display the field entered into the DataTextField (using {0}).

 

Can ayone tell me how to expose further fields to use in this property, so that I can enter for example,

 

DataTextFormatField = {0} - {1}, {2}

 

Thanks for any help on this.

 

Cheers,

IAmGuyster:D

Posted

Done and Done

 

After a fair bit of searching, I found something that tells me I cannot expose two of the fields using the properties UI. Instead it has to be done programmatically. If anyone is interested I will post a smple of the code I used. It's very simple.

 

Cheers,

IAmGuyster

  • Moderators
Posted

A simple solution would to format the Select from your DB...

 

SELECT (F2 + ' - ' + F3 + ', ' + F4) as SomeF, F4 From ....

 

Then do something like this...

 

DataTextField = SomeF

DataValueField = F4

Visit...Bassic Software
Posted

In the dataset where you are holding the dropdownlist data, you should be able to assign the text for the ddl by using the following structure to populate the ddl:

 

{Assume the query returns the fields in this order: Field1, Field2, Field3, Field4, where field1 is item 0, field2 is item 1, etc.}

{Also assume that the name of your drop down list is myddl}

 

Dim myset as Dataset = [you dataset info here]

Dim mytable As DataTable = myset.Tables(0)

Dim j As Integer

For j = 0 to mytable.rows.count - 1

Dim mylistitem As New System.Web.UI.WebControls.ListItem

mylistitem.Text = mytable.Rows(j).Item(1) & " - " & mytable.rows(j).Item(2) & ", " & mytable.rows.Item(3)

mylistitem.Value = mytable.Rows(j).Item(1)

myddl.Add(mylistitem)

mylistitem = Nothing

Next

 

Hope this helps!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...