Thursday, March 29, 2012

List Box

Hi Guys,

I need to append space in front of Directory names inside listbox based on
the folder level inside directory.

If i do
lBoxLocation.Items.Add(new ListItem(" "+
dirInfo[i].Name,dirInfo(i).FullName))

it adds in front of value. If i put white space, it dont appear at all.

Can someone tell me or guide me to an example which shows how to work with
this?

Thanks

MannyTry running your string through an HtmlDecode:

dim spaces as string = DecodedSpaces(2)
lBoxLocation.Items.Add(spaces + dirInfo[i].Name,dirInfo(i).FullName)

public shared function DecodedSpaces(numberOfSpaces as integer) as string
dim spaces as string = ""
for i as integer = 0 to numberofSpaces - 1
spaces &= " "
next
return HttpUtility.HtmlDecode(spaces)
end function

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

"Manny Chohan" <MannyChohan@.discussions.microsoft.com> wrote in message
news:15F021DD-2ABC-4F7C-96F8-8D3209CCC0B8@.microsoft.com...
> Hi Guys,
> I need to append space in front of Directory names inside listbox based on
> the folder level inside directory.
> If i do
> lBoxLocation.Items.Add(new ListItem(" "+
> dirInfo[i].Name,dirInfo(i).FullName))
> it adds in front of value. If i put white space, it dont appear at all.
> Can someone tell me or guide me to an example which shows how to work with
> this?
> Thanks
> Manny
"Manny Chohan" <MannyChohan@.discussions.microsoft.com> wrote in message news:15F021DD-2ABC-4F7C-96F8-8D3209CCC0B8@.microsoft.com...
> I need to append space in front of Directory names inside listbox based on
: :
> it adds in front of value. If i put white space, it dont appear at all.

Manny,

Whitespace will be normalized by the browser, so no matter how many consecutive
spaces you send they'll appear as only one on the user's screen.

What you need to do is prepend non-breaking spaces, , which the browser
won't force normalization of, e.g.,

lBoxLocation.Items.Add(new ListItem(" " + _
dirInfo[i].Name,dirInfo(i).FullName))

Each will take up one space when seen in the browser by the user.

Derek Harmon

List bound controls

Hi,

I have been reading information about asp.net webcontrols, and i have
found a term "List bound controls".

What are "List Bound Controls"?? Which are the differences between
these controls and the others?? how many webcontrols are list bound
controls?? any url in microsoft.com talking about lista bound
controls??

Any help would be very appreciate.

Thanks,

Alfredo BarrientosAlfredo,

List-Bound controls are any control that may be databound to a list of data
(usually retrieved from a database) these would include many controls
because almost any control may be databound. But controls that can actually
bind to every item in a list of data are ones such as CheckBoxList,
RadioButtonList, Datagrid, DataList, and Repeater.

To find out more information on these and other bindable controls I would
suggest starting with a few of the databinding tutorials which may be found
here: http://samples.gotdotnet.com/quickstart/aspplus/

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Alfredo Barrientos" <abarrientos@.gmail.com> wrote in message
news:1129519240.655592.95510@.z14g2000cwz.googlegro ups.com...
> Hi,
> I have been reading information about asp.net webcontrols, and i have
> found a term "List bound controls".
> What are "List Bound Controls"?? Which are the differences between
> these controls and the others?? how many webcontrols are list bound
> controls?? any url in microsoft.com talking about lista bound
> controls??
> Any help would be very appreciate.
> Thanks,
> Alfredo Barrientos
Thanks Justin,

In your page I cant find the documentation about ListBound controls.
Could Any ASP.Net MVP answer this question??

Thanks,

Alfredo Barrientos

List bound controls

Hi,
I have been reading information about asp.net webcontrols, and i have
found a term "List bound controls".
What are "List Bound Controls"' Which are the differences between
these controls and the others' how many webcontrols are list bound
controls' any url in microsoft.com talking about lista bound
controls'
Any help would be very appreciate.
Thanks,
Alfredo BarrientosAlfredo,
List-Bound controls are any control that may be databound to a list of data
(usually retrieved from a database) these would include many controls
because almost any control may be databound. But controls that can actually
bind to every item in a list of data are ones such as CheckBoxList,
RadioButtonList, Datagrid, DataList, and Repeater.
To find out more information on these and other bindable controls I would
suggest starting with a few of the databinding tutorials which may be found
here: http://samples.gotdotnet.com/quickstart/aspplus/
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Alfredo Barrientos" <abarrientos@.gmail.com> wrote in message
news:1129519240.655592.95510@.z14g2000cwz.googlegroups.com...
> Hi,
> I have been reading information about asp.net webcontrols, and i have
> found a term "List bound controls".
> What are "List Bound Controls"' Which are the differences between
> these controls and the others' how many webcontrols are list bound
> controls' any url in microsoft.com talking about lista bound
> controls'
> Any help would be very appreciate.
> Thanks,
> Alfredo Barrientos
>
Thanks Justin,
In your page I cant find the documentation about ListBound controls.
Could Any ASP.Net MVP answer this question'
Thanks,
Alfredo Barrientos

list box

I have a list box that is populated from my dataset. I add a new item in
there called "ALL". In this list box the user can select more then one item,
my question is, if they select ALL can i disable the multi selection
capability? So if ALL is selected they can't hold down the CTRL key and
select more.I believe, there is no builtin property in listbox control for this

but, this is simple to implement in javascript.. you will not be able to
disable some options in a select box but will be able to deselect the other
selections or display a message if ALL is selected.

Following function would deselect all except first item in the list...

function Deselect()
{
var theDayElement = window.document.form1.cmbDay

var optionCounter;
for (optionCounter = 1; optionCounter < theDayElement.length;
optionCounter++)
{
theDayElement.options[optionCounter].selected=false;
}
}

This function would check if first option (ALL) is selected and call
deselect() to deselect all other options

function CheckValue()
{
if(window.document.form1.cmbDay.options[0].selected == true)
DeselectAll();
}

your Select tag would look like below

<SELECT NAME="cmbDay" ID="cmbDay" multiple onchange="CheckValue();"
Hope this helps...

"NuB" wrote:

> I have a list box that is populated from my dataset. I add a new item in
> there called "ALL". In this list box the user can select more then one item,
> my question is, if they select ALL can i disable the multi selection
> capability? So if ALL is selected they can't hold down the CTRL key and
> select more.
>
>
>

list box

I have a list box that is populated from my dataset. I add a new item in
there called "ALL". In this list box the user can select more then one item,
my question is, if they select ALL can i disable the multi selection
capability? So if ALL is selected they can't hold down the CTRL key and
select more.I believe, there is no builtin property in listbox control for this
but, this is simple to implement in javascript.. you will not be able to
disable some options in a select box but will be able to deselect the other
selections or display a message if ALL is selected.
Following function would deselect all except first item in the list...
function Deselect()
{
var theDayElement = window.document.form1.cmbDay
var optionCounter;
for (optionCounter = 1; optionCounter < theDayElement.length;
optionCounter++)
{
theDayElement.options[optionCounter].selected=false;
}
}
This function would check if first option (ALL) is selected and call
deselect() to deselect all other options
function CheckValue()
{
if( window.document.form1.cmbDay.options[0].selected == true)
DeselectAll();
}
your Select tag would look like below
<SELECT NAME="cmbDay" ID="cmbDay" multiple onchange="CheckValue();">
Hope this helps...
"NuB" wrote:

> I have a list box that is populated from my dataset. I add a new item in
> there called "ALL". In this list box the user can select more then one ite
m,
> my question is, if they select ALL can i disable the multi selection
> capability? So if ALL is selected they can't hold down the CTRL key and
> select more.
>
>
>

List Box

Hi Guys,
I need to append space in front of Directory names inside listbox based on
the folder level inside directory.
If i do
lBoxLocation.Items.Add(new ListItem(" "+
dirInfo[i].Name,dirInfo(i).FullName))
it adds in front of value. If i put white space, it dont appear at all.
Can someone tell me or guide me to an example which shows how to work with
this?
Thanks
MannyTry running your string through an HtmlDecode:
dim spaces as string = DecodedSpaces(2)
lBoxLocation.Items.Add(spaces + dirInfo[i].Name,dirInfo(i).FullName)
public shared function DecodedSpaces(numberOfSpaces as integer) as string
dim spaces as string = ""
for i as integer = 0 to numberofSpaces - 1
spaces &= " "
next
return HttpUtility.HtmlDecode(spaces)
end function
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Manny Chohan" <MannyChohan@.discussions.microsoft.com> wrote in message
news:15F021DD-2ABC-4F7C-96F8-8D3209CCC0B8@.microsoft.com...
> Hi Guys,
> I need to append space in front of Directory names inside listbox based on
> the folder level inside directory.
> If i do
> lBoxLocation.Items.Add(new ListItem(" "+
> dirInfo[i].Name,dirInfo(i).FullName))
> it adds in front of value. If i put white space, it dont appear at all.
> Can someone tell me or guide me to an example which shows how to work with
> this?
> Thanks
> Manny
>
"Manny Chohan" <MannyChohan@.discussions.microsoft.com> wrote in message news:15F021DD-2ABC-
4F7C-96F8-8D3209CCC0B8@.microsoft.com...
> I need to append space in front of Directory names inside listbox based on
: :
> it adds in front of value. If i put white space, it dont appear at all.
Manny,
Whitespace will be normalized by the browser, so no matter how many consecut
ive
spaces you send they'll appear as only one on the user's screen.
What you need to do is prepend non-breaking spaces, , which the browse
r
won't force normalization of, e.g.,
lBoxLocation.Items.Add(new ListItem(" " + _
dirInfo[i].Name,dirInfo(i).FullName))
Each will take up one space when seen in the browser by the user.
Derek Harmon

List Box and different color

There is a way to give different color to listitems of a ListBox ?Yes, it is, but needs a bit work as basically it would need to be done so
that every ListItem in the ListBox has custom style attributes. Those
attributes are then rendered at the HTML. Only problem is that this works by
default only in HtmlSelect control.

See:
http://support.microsoft.com/defaul...kb;en-us;309338

So if you absolutely need ListBox, you would need to rewrite some
implementation for the control.

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
joteke@.aspalliance.com

"Alessandro" <gemini_two@.hotmail.com> kirjoitti viestiss
news:eNohrkhQDHA.2320@.TK2MSFTNGP12.phx.gbl...
> There is a way to give different color to listitems of a ListBox ?

List Box and DataValue field

I populate a listbox from a query. Now I want to retrieve the datavalue field of the selected row. The datavalue field related to the PK and pass it in the querystring.

How do you do this?

Try listbox.selectedValue

List Box Code Behind Problem

I have a list box called cboProducts with a code behind function called cboProducts_SelectedIndexChanged() that's associated with the IndexChanged event.

Here's the code behind function

Public Sub cboProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboProducts.SelectedIndexChanged

Dim i

i = cboProducts.SelectedIndex
txtBox.Text = cboProducts.Items(selIndex).Text
End Sub


The problem is that "i" never changes from -1 no matter which option I select.

I'm trying to capture the users selected index in the list box.

What am I doing wrong?

thanks.

ddMaybe the problem is in the Page_Load event where you're probably binding a datasource to the list with products. The point is, you should a "if not page.IsPostback then" decision structure, so that the data is only bound to the controls when the page is loaded the very first time (not during postbacks). Does this help you to solve your problem?
That did it.

Thanks a million.

doug

List box forgets the items selected

Hi,

I am using a htmlinputbutton rather than webcontrols.button as i need to do server as well as client scripting. There is a list box whose items get submitted on click of this button. problem is that selected property of listitem works fine with webcontrol button click and does not works with htmlinputbutton_serverclick.
------------------
foreach (ListItem item in StepsListBox.Items)
{
if (item.Selected)
{
response.write(item.text);
}
}
---------------

Any ideas??

Thanks,
pradeepTry getting your items out of the Request.Form if you must use that Html button.
Thanks for the response.

Request.Form["listboxName"] does not seems to be working. It does not returns back the selected items.

I am ready to use webcontrols.button but problem is its server side click event does not gets called if i am calling javascript click function also using following code:
------------------
Button1.Attributes.Add("onClick","clientfunction");
------------------
I added this code in the page_load event.

Please help. I am stuck. I am not able to proceed neither with webcontrol button not htmlbutton. My aim is to call client as well as server script on button click, and i shud be able to get selected items of a listbox in the form on server side.

Thanks,
Pradeep
Your server-side could should still run when you add client-side JavaScript to the onClick. Try:

Button1.Attributes.Add("onClick", "JavaScript:clientFunction();");
Thanks again.

It worked this time. Problem was that i was disabling the controls in the client script and so server events were not firing.

But disabling controls is the requirement. I have to somehow show form busy and controls disabled until i get response from server. I am thinking now some another way to show form as busy.

thanks,
Pradeep

List Box Heading

Hello,

How do I insert non-selectable headings into a list box?

e.g. if i had a list box displaying cities around the world - how could
i insert the country's name above each goup of cities

Australia (heading)
Sydney
Melbourne
New Zealand (heading)
Auckland
Wellington

Thanks!

JackJack -e

I don't think thats possible to make an unselectable listitem, without using
a javascript. A work around would be to just redisplay the form if a country
is selected with a message like "Please select a city in Spain."

Good Luck
DWS

"jack-e" wrote:

> Hello,
> How do I insert non-selectable headings into a list box?
> e.g. if i had a list box displaying cities around the world - how could
> i insert the country's name above each goup of cities
> Australia (heading)
> Sydney
> Melbourne
> New Zealand (heading)
> Auckland
> Wellington
> Thanks!
> Jack
>

List Box Heading

Hello,
How do I insert non-selectable headings into a list box?
e.g. if i had a list box displaying cities around the world - how could
i insert the country's name above each goup of cities
Australia (heading)
Sydney
Melbourne
New Zealand (heading)
Auckland
Wellington
Thanks!
JackJack -e
I don't think thats possible to make an unselectable listitem, without using
a javascript. A work around would be to just redisplay the form if a countr
y
is selected with a message like "Please select a city in Spain."
Good Luck
DWS
"jack-e" wrote:

> Hello,
> How do I insert non-selectable headings into a list box?
> e.g. if i had a list box displaying cities around the world - how could
> i insert the country's name above each goup of cities
> Australia (heading)
> Sydney
> Melbourne
> New Zealand (heading)
> Auckland
> Wellington
> Thanks!
> Jack
>

List box giving me error

I am getting an error on my Dropdownlist box if there is nothing in it when
I double click on the item I want to look at. I have the ddl setup to allow
double clicks on the items to look at like so:
Me.StoredSearches.Attributes("ondblClick") =
"__doPostBack('LbxSender','')"
If Request.Form("__EVENTTARGET") = "LbxSender" Then
Dim strSelected As String
strSelected = StoredSearches.SelectedItem.Value.ToString
Call SelectSearch(strSelected)
trace.warn("storedSearches.SelectedItem is nothing")
End If
If there is nothing in the box and you double click anywhere, you get the
following error:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
If there is at least one item in the ddl and you haven't already selected
anything, you will get the next index after the last item. For example, if
there is 1 item in the ddl (which would be index 0), you will get 1.
If there is nothing, in the box - you get the error:
I can fix it by doing this:
If Request.Form("__EVENTTARGET") = "LbxSender" Then
Dim strSelected As String
if not storedSearches.SelectedItem is nothing then
strSelected = StoredSearches.SelectedItem.Value.ToString
Call SelectSearch(strSelected)
else
trace.warn("storedSearches.SelectedItem is nothing")
end if
End If
All I do is check if "storedSearches.SelectedItem" (my dropdownlist) is
nothing.
I would have thought that I would get a -1 as an index.
If there is nothing in the ddl and you double click and you get null
(nothing) for the selectedItem, why wouldn't you get the same for selecting
an item past the list?
Thanks,
TomNever mind.
Had a little brain fade.
I should have been looking at SelectedIndex (which will be set to -1) and
not SelectedItem.
Tom
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:ulraNOuPFHA.3788@.tk2msftngp13.phx.gbl...
>I am getting an error on my Dropdownlist box if there is nothing in it when
>I double click on the item I want to look at. I have the ddl setup to
>allow double clicks on the items to look at like so:
> Me.StoredSearches.Attributes("ondblClick") =
> "__doPostBack('LbxSender','')"
> If Request.Form("__EVENTTARGET") = "LbxSender" Then
> Dim strSelected As String
> strSelected = StoredSearches.SelectedItem.Value.ToString
> Call SelectSearch(strSelected)
> trace.warn("storedSearches.SelectedItem is nothing")
> End If
> If there is nothing in the box and you double click anywhere, you get the
> following error:
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
> If there is at least one item in the ddl and you haven't already selected
> anything, you will get the next index after the last item. For example,
> if there is 1 item in the ddl (which would be index 0), you will get 1.
> If there is nothing, in the box - you get the error:
> I can fix it by doing this:
> If Request.Form("__EVENTTARGET") = "LbxSender" Then
> Dim strSelected As String
> if not storedSearches.SelectedItem is nothing then
> strSelected = StoredSearches.SelectedItem.Value.ToString
> Call SelectSearch(strSelected)
> else
> trace.warn("storedSearches.SelectedItem is nothing")
> end if
> End If
> All I do is check if "storedSearches.SelectedItem" (my dropdownlist) is
> nothing.
> I would have thought that I would get a -1 as an index.
> If there is nothing in the ddl and you double click and you get null
> (nothing) for the selectedItem, why wouldn't you get the same for
> selecting an item past the list?
> Thanks,
> Tom
>
Actually,
I did find that if there is something in the ddl and you select below the
last item (and nothing is selected at the time), you will get a 0 as
SelectedIndex (instead of -1) and whatever ..items.count is.
Why is this?
This would mean that the only way to test if there was a valid choice is to
check first if item.count is = 0 (to see if there is anything in the list)
and then to see if the SelectedItem = ..items.count (not a valid choice).
SelectedIndex doesn't help as it would be 0 (which is valid - just not what
was chosen).
Tom
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:eEwh8zuPFHA.164@.TK2MSFTNGP12.phx.gbl...
> Never mind.
> Had a little brain fade.
> I should have been looking at SelectedIndex (which will be set to -1) and
> not SelectedItem.
> Tom
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:ulraNOuPFHA.3788@.tk2msftngp13.phx.gbl...
>

List box giving me error

I am getting an error on my Dropdownlist box if there is nothing in it when
I double click on the item I want to look at. I have the ddl setup to allow
double clicks on the items to look at like so:

Me.StoredSearches.Attributes("ondblClick") =
"__doPostBack('LbxSender','')"

If Request.Form("__EVENTTARGET") = "LbxSender" Then
Dim strSelected As String
strSelected = StoredSearches.SelectedItem.Value.ToString
Call SelectSearch(strSelected)
trace.warn("storedSearches.SelectedItem is nothing")
End If

If there is nothing in the box and you double click anywhere, you get the
following error:

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

If there is at least one item in the ddl and you haven't already selected
anything, you will get the next index after the last item. For example, if
there is 1 item in the ddl (which would be index 0), you will get 1.

If there is nothing, in the box - you get the error:

I can fix it by doing this:
If Request.Form("__EVENTTARGET") = "LbxSender" Then
Dim strSelected As String
if not storedSearches.SelectedItem is nothing then
strSelected = StoredSearches.SelectedItem.Value.ToString
Call SelectSearch(strSelected)
else
trace.warn("storedSearches.SelectedItem is nothing")
end if
End If

All I do is check if "storedSearches.SelectedItem" (my dropdownlist) is
nothing.

I would have thought that I would get a -1 as an index.

If there is nothing in the ddl and you double click and you get null
(nothing) for the selectedItem, why wouldn't you get the same for selecting
an item past the list?

Thanks,

TomNever mind.

Had a little brain fade.

I should have been looking at SelectedIndex (which will be set to -1) and
not SelectedItem.

Tom
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:ulraNOuPFHA.3788@.tk2msftngp13.phx.gbl...
>I am getting an error on my Dropdownlist box if there is nothing in it when
>I double click on the item I want to look at. I have the ddl setup to
>allow double clicks on the items to look at like so:
> Me.StoredSearches.Attributes("ondblClick") =
> "__doPostBack('LbxSender','')"
> If Request.Form("__EVENTTARGET") = "LbxSender" Then
> Dim strSelected As String
> strSelected = StoredSearches.SelectedItem.Value.ToString
> Call SelectSearch(strSelected)
> trace.warn("storedSearches.SelectedItem is nothing")
> End If
> If there is nothing in the box and you double click anywhere, you get the
> following error:
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
> If there is at least one item in the ddl and you haven't already selected
> anything, you will get the next index after the last item. For example,
> if there is 1 item in the ddl (which would be index 0), you will get 1.
> If there is nothing, in the box - you get the error:
> I can fix it by doing this:
> If Request.Form("__EVENTTARGET") = "LbxSender" Then
> Dim strSelected As String
> if not storedSearches.SelectedItem is nothing then
> strSelected = StoredSearches.SelectedItem.Value.ToString
> Call SelectSearch(strSelected)
> else
> trace.warn("storedSearches.SelectedItem is nothing")
> end if
> End If
> All I do is check if "storedSearches.SelectedItem" (my dropdownlist) is
> nothing.
> I would have thought that I would get a -1 as an index.
> If there is nothing in the ddl and you double click and you get null
> (nothing) for the selectedItem, why wouldn't you get the same for
> selecting an item past the list?
> Thanks,
> Tom
Actually,

I did find that if there is something in the ddl and you select below the
last item (and nothing is selected at the time), you will get a 0 as
SelectedIndex (instead of -1) and whatever ..items.count is.

Why is this?

This would mean that the only way to test if there was a valid choice is to
check first if item.count is = 0 (to see if there is anything in the list)
and then to see if the SelectedItem = ..items.count (not a valid choice).
SelectedIndex doesn't help as it would be 0 (which is valid - just not what
was chosen).

Tom
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:eEwh8zuPFHA.164@.TK2MSFTNGP12.phx.gbl...
> Never mind.
> Had a little brain fade.
> I should have been looking at SelectedIndex (which will be set to -1) and
> not SelectedItem.
> Tom
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:ulraNOuPFHA.3788@.tk2msftngp13.phx.gbl...
>>I am getting an error on my Dropdownlist box if there is nothing in it
>>when I double click on the item I want to look at. I have the ddl setup
>>to allow double clicks on the items to look at like so:
>>
>> Me.StoredSearches.Attributes("ondblClick") =
>> "__doPostBack('LbxSender','')"
>>
>> If Request.Form("__EVENTTARGET") = "LbxSender" Then
>> Dim strSelected As String
>> strSelected = StoredSearches.SelectedItem.Value.ToString
>> Call SelectSearch(strSelected)
>> trace.warn("storedSearches.SelectedItem is nothing")
>> End If
>>
>> If there is nothing in the box and you double click anywhere, you get the
>> following error:
>>
>> Exception Details: System.NullReferenceException: Object reference not
>> set to an instance of an object.
>>
>> If there is at least one item in the ddl and you haven't already selected
>> anything, you will get the next index after the last item. For example,
>> if there is 1 item in the ddl (which would be index 0), you will get 1.
>>
>> If there is nothing, in the box - you get the error:
>>
>> I can fix it by doing this:
>> If Request.Form("__EVENTTARGET") = "LbxSender" Then
>> Dim strSelected As String
>> if not storedSearches.SelectedItem is nothing then
>> strSelected = StoredSearches.SelectedItem.Value.ToString
>> Call SelectSearch(strSelected)
>> else
>> trace.warn("storedSearches.SelectedItem is nothing")
>> end if
>> End If
>>
>> All I do is check if "storedSearches.SelectedItem" (my dropdownlist) is
>> nothing.
>>
>> I would have thought that I would get a -1 as an index.
>>
>> If there is nothing in the ddl and you double click and you get null
>> (nothing) for the selectedItem, why wouldn't you get the same for
>> selecting an item past the list?
>>
>> Thanks,
>>
>> Tom
>>

List Box help

I have a web application where I have two List boxes side by side on the form. The first one lists all the available projects. When a project is selected, and a button is clicked, the data is transfered into the other list box. I know I could just set the selection mode of the list box to multiple but I am trying to make it easier for my users. On submitting the form, I wish to capture all the items that has been transfered into the second listbox. Is it possible to do this without the items in the second listbox been selected? A URL to this problem is:

http://cms-stu-iis.gre.ac.uk/as015/project/question.aspx

The code I have is :


<%@dotnet.itags.org. Page Language="VB"%
<script runat="server"
Sub Page_Load(sender as Object, e as EventArgs)

End Sub

Sub btnAdd_Click(sender as Object, e as EventArgs)
'Check to see if it has already been selected, add it if it's not
If lstProjectsAdd.Items.FindByValue(lstProjects.SelectedValue) is Nothing AND lstProjects.SelectedValue <> "" Then
lstProjectsAdd.Items.Add(new ListItem(lstProjects.SelectedItem.Text, lstProjects.SelectedValue))
'Remove Item from the source control, You can take this line out if you think it is not necessary
lstProjects.Items.Remove(lstProjects.Items.FindByValue(lstProjects.SelectedValue))
'lstPAdd.Items.FindByValue("10").Selected = true
End If
End Sub

Sub btnSubtract_Click(sender as Object, e as EventArgs)
'Check to see if it has already been selected, add it if it's not
If lstProjects.Items.FindByValue(lstProjectsAdd.SelectedValue) is Nothing AND lstProjectsAdd.SelectedValue <> "" Then
'Comment out this line if you took out the feature in "btnAdd_Click" Click event
lstProjects.Items.Add(new ListItem(lstProjectsAdd.SelectedItem.Text, lstProjectsAdd.SelectedValue))
'Remove Item from the source control
lstProjectsAdd.Items.Remove(lstProjectsAdd.Items.FindByValue(lstProjectsAdd.SelectedValue))
End If
End Sub

</Script
<form runat="server">
<Table>
<tr>
<td>Available Projects</td><td> </td><td>Selected Projects</td>
</tr>
<tr>
<td><asp:ListBox id="lstProjects" runat="server" Width="200px" Height="137px">
<asp:ListItem value="1">SkyWise</asp:ListItem>
<asp:ListItem value="2">B2B For Neta</asp:ListItem>
<asp:ListItem value="3">James Norton LTD</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:Button id="btnAdd" runat="server" Width="42px" Text=">>" onclick="btnAdd_Click"></asp:Button>
<br>
<asp:Button id="btnSubtract" runat="server" Width="42px" Text="<<" onclick="btnSubtract_Click"></asp:Button>
</td>
<td><asp:ListBox id="lstProjectsAdd" runat="server" Width="200px" Height="137px" SelectionMode="Multiple"
</asp:ListBox>
</td>
</tr>
<tr>
<td colspan="3"><asp:Button id="btnSubmit" runat="server" Width="122px" Text="Add Data"></asp:Button></td>
</tr>
</table>
</form

Thanks .I've updated your code to handle the Add Data button. It reports which items were selected. Hopefully this will demonstrate how to capture the items that have been added to the second listbox.

<%@. Page Language="VB"%>
<script runat="server"
Sub Page_Load(sender as Object, e as EventArgs)

End Sub

Sub btnAdd_Click(sender as Object, e as EventArgs)
'Check to see if it has already been selected, add it if it's not
If lstProjectsAdd.Items.FindByValue(lstProjects.SelectedValue) is Nothing AND lstProjects.SelectedValue <> "" Then
lstProjectsAdd.Items.Add(new ListItem(lstProjects.SelectedItem.Text, lstProjects.SelectedValue))
'Remove Item from the source control, You can take this line out if you think it is not necessary
lstProjects.Items.Remove(lstProjects.Items.FindByValue(lstProjects.SelectedValue))
'lstPAdd.Items.FindByValue("10").Selected = true
End If
End Sub

Sub btnSubtract_Click(sender as Object, e as EventArgs)
'Check to see if it has already been selected, add it if it's not
If lstProjects.Items.FindByValue(lstProjectsAdd.SelectedValue) is Nothing AND lstProjectsAdd.SelectedValue <> "" Then
'Comment out this line if you took out the feature in "btnAdd_Click" Click event
lstProjects.Items.Add(new ListItem(lstProjectsAdd.SelectedItem.Text, lstProjectsAdd.SelectedValue))
'Remove Item from the source control
lstProjectsAdd.Items.Remove(lstProjectsAdd.Items.FindByValue(lstProjectsAdd.SelectedValue))
End If
End Sub

Sub btnSubmit_Click(sender as Object, e as EventArgs)
Message.Text = "Selected items:<br />"
Dim thisItem As ListItem
For Each thisItem in lstProjectsAdd.Items
Message.Text &= thisItem.Text & "<br />"
Next
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<Table>
<tr>
<td>Available Projects</td><td> </td><td>Selected Projects</td>
</tr>
<tr>
<td><asp:ListBox id="lstProjects" runat="server" Width="200px" Height="137px">
<asp:ListItem value="1">SkyWise</asp:ListItem>
<asp:ListItem value="2">B2B For Neta</asp:ListItem>
<asp:ListItem value="3">James Norton LTD</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:Button id="btnAdd" runat="server" Width="42px" Text=">>" onclick="btnAdd_Click"></asp:Button>
<br>
<asp:Button id="btnSubtract" runat="server" Width="42px" Text="<<" onclick="btnSubtract_Click"></asp:Button>
</td>
<td><asp:ListBox id="lstProjectsAdd" runat="server" Width="200px" Height="137px" SelectionMode="Multiple"
</asp:ListBox>
</td>
</tr>
<tr>
<td colspan="3"><asp:Button id="btnSubmit" runat="server" Width="122px" onclick="btnSubmit_Click" Text="Add Data"></asp:Button></td>
</tr>
</table>
<asp:Label id="Message" enableviewstate="False" runat="server" />
</form>
</body>
</html>


By the way, there is an existing control that does what you're seeking:DualList

One thing it does, that your method does not, is allow the items to be moved back and forth without forcing a postback every time.

It is free and open-source. So, it's an option to keep in mind.
Thank you so much for the response. The control looks even better.
There are some great controls on theMetaBuilders site. At the moment, they are all free and open-source. So, it's a great place to bookmark.

But, there's great educational value in developing your own controls and mechanisms. You've almost finished your own Dual ListBox system, and you've done well. Why not finish your own system for its educational value? Then, when the warm glow of finishing your own system has faded, you can switch to the MetaBuilder's control ...
It's a good idea, I've always wanted to write my own controls but unfortunately I have not had the time to learn how to go about it yet, as i've only been using .net for just under a year. I'll definitely be doing that very soon.
Oh, I didn't mean turning it into an actual server control. Believe me, that's harder than you'd think! (Though a User Control would be easy.)

I only meant you could proceed with what you have; get it working on the page exactly as you have it now. That is, finish the task you set yourself. Again, just for the educational value.

Just a thought ...
I'm coming in late on this one, but it might be worth your while to check outEasyListBox as well; it doesn't have many of the limitations of the DualList control -- which is still great for a free control -- and it's based on the EasyListBox rendering engine, so you have a whole lot more features as well.

List Box issue, suggestions?

Hi all!

I have a list box that's populated from a DB. I know that you can't copy (ctrl-c) from a list box so, what should I use so the user will be able to do a copy from there to place in another application?

Thanks

Mike

Hi, Do you want to allow the user the ability to copy values from the list box control, so that they can add to, say ms word?


Yes


You could create it so that selected values are added to a textbox and then that textbox can be highlighted and pasted into word. Would that work ok for your project?


As simple solution is to add the selected text to a label, and copy the content of the label.

Or build a button 'Copy to clipboard' this link may help?http://www.geekpedia.com/tutorial126_Clipboard-cut-copy-and-paste-with-JavaScript.html


yeah, i think that would work ok.

Thanks guys!!


IE has specific JavaScript function(s) to get/set clipboard data: http://msdn2.microsoft.com/en-us/library/ms535220.aspx . For e.g., you may have a simple JS function calling the setData() after deciding what data to copy from the list box. Then invoke the JS function with a button (Copy to Clipboard) click.

Hope this helps.

List box is populated with data belongs to another user

I have a list box in my ASP.NET web page. The list box is populated on page load event with names of the employees of a department. The department is decided depends on the login. But when a user from department "A" logs in, he is shocked to see employees of other department in his list box i.e. other than A. He logs out and re logs the problem is solved he gets back his employees. This problem frequently occurs. What could be the problem ? Please mail togsnsarma@dotnet.itags.org.rediffmail.com orgsnsarma@dotnet.itags.org.yahoo.com

Post the code that's filling your list box.

list box no selection

if(listBox.SelectedItem.Text != null)
{
// test
}
This code gives exception if no item is selected in the list box, how can I
check if any item is selected or not?try testing SelectedItem for null instead, before using the property.
JIM.H. wrote:
> if(listBox.SelectedItem.Text != null)
> {
> // test
> }
> This code gives exception if no item is selected in the list box, how can
I
> check if any item is selected or not?
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:74BB25D8-D47E-468C-93BC-BF1B57D7E044@.microsoft.com...

> if(listBox.SelectedItem.Text != null)
> {
> // test
> }
> This code gives exception if no item is selected in the list box, how can
> I
> check if any item is selected or not?
if(listBox.SelectedIndex == -1)
{
// no items selected
}

List Box Populated Client Side

I have a list box which gets populated client side (Javascript).

Now when I submit the page - I need to capture all the list item and
store it in database.

What is the elegant way to do it in asp.net?

Thanks
KMOn Mon, 26 Dec 2005 09:55:56 -0800, math.kiran wrote:

> I have a list box which gets populated client side (Javascript).
> Now when I submit the page - I need to capture all the list item and
> store it in database.
> What is the elegant way to do it in asp.net?
> Thanks
> KM
Use XML to encode the option array
corresponding to the select in a hidden type field. To this effect
you either enumerate the option array, or give all the options the same id
(as in <option id=myoption value=1>one</option>) and enumerate
document.all.myoption.
You should build xml like:
<myoption value=1>
<myoption value=2>
...

Once you receive the object representing the options you can store this in
the database via a stored procedure that accepts the XML as a parameter,
loads the XML into a temporary dom and processes this dom via a select.
Are you saying to create a client side XML data island.

Yes that is a way to go -- but don't you think it might be a problem
with browsers like firefox etc.

Thanks
On Mon, 26 Dec 2005 11:22:53 -0800, JaduBlue wrote:

> Are you saying to create a client side XML data island.
> Yes that is a way to go -- but don't you think it might be a problem
> with browsers like firefox etc.
> Thanks
A data island is one possibility. However, what I suggest is just a hidden
variable that contains the XML for a collection of <option>s
I hope this is clear.
Hi,
There is an indirect way to get all the list items at the server side
which are added from the client side javascript.
We can retrieve all the list items(only the selected list item values)
using
Request.Form("lstCountries")

So before posting back to the server, make all the list items selected
= true.
using the script code function call
like

function selAll(){
var lst = document.getElementById("lst1");
var j=0;
for(j=lst.length-1;j>=0;j--){
lst.options[j].selected=true;
}
}

THen at the server side, just retrieve using Request.Form("lst1");

Bye,
Praveen P.

List Box Populated Client Side

I have a list box which gets populated client side (Javascript).
Now when I submit the page - I need to capture all the list item and
store it in database.
What is the elegant way to do it in asp.net?
Thanks
KMOn Mon, 26 Dec 2005 09:55:56 -0800, math.kiran wrote:

> I have a list box which gets populated client side (Javascript).
> Now when I submit the page - I need to capture all the list item and
> store it in database.
> What is the elegant way to do it in asp.net?
> Thanks
> KM
Use XML to encode the option array
corresponding to the select in a hidden type field. To this effect
you either enumerate the option array, or give all the options the same id
(as in <option id=myoption value=1>one</option> ) and enumerate
document.all.myoption.
You should build xml like:
<myoption value=1>
<myoption value=2>
...
Once you receive the object representing the options you can store this in
the database via a stored procedure that accepts the XML as a parameter,
loads the XML into a temporary dom and processes this dom via a select.
Are you saying to create a client side XML data island.
Yes that is a way to go -- but don't you think it might be a problem
with browsers like firefox etc.
Thanks
On Mon, 26 Dec 2005 11:22:53 -0800, JaduBlue wrote:

> Are you saying to create a client side XML data island.
> Yes that is a way to go -- but don't you think it might be a problem
> with browsers like firefox etc.
> Thanks
A data island is one possibility. However, what I suggest is just a hidden
variable that contains the XML for a collection of <option>s
I hope this is clear.
Hi,
There is an indirect way to get all the list items at the server side
which are added from the client side javascript.
We can retrieve all the list items(only the selected list item values)
using
Request.Form("lstCountries")
So before posting back to the server, make all the list items selected
= true.
using the script code function call
like
function selAll(){
var lst = document.getElementById("lst1");
var j=0;
for(j=lst.length-1;j>=0;j--){
lst.options[j].selected=true;
}
}
THen at the server side, just retrieve using Request.Form("lst1");
Bye,
Praveen P.

list box no selection

if(listBox.SelectedItem.Text != null)
{
// test
}

This code gives exception if no item is selected in the list box, how can I
check if any item is selected or not?try testing SelectedItem for null instead, before using the property.

JIM.H. wrote:

Quote:

Originally Posted by

if(listBox.SelectedItem.Text != null)
{
// test
}
>
This code gives exception if no item is selected in the list box, how can I
check if any item is selected or not?


"JIM.H." <JIMH@.discussions.microsoft.comwrote in message
news:74BB25D8-D47E-468C-93BC-BF1B57D7E044@.microsoft.com...

Quote:

Originally Posted by

if(listBox.SelectedItem.Text != null)
{
// test
}
>
This code gives exception if no item is selected in the list box, how can
I
check if any item is selected or not?


if(listBox.SelectedIndex == -1)
{
// no items selected
}

List box problem

(Type your message here)
From: Asp Net
Hi all,
I have list box in web form. I am populating 2 coloums in the list box. My p
roblem is I need space between two coloumns.
lstList.Items.Add(Coloumn& " " & Coloumn) this is not working. What to do?
Thanks in advance
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>KL7ZpYRKnUSYXzSOYGGrFg==</Id>Hi,
I come acrossed the same problem, what i did is I write the sql query which
concatenate the two column and return it as a single column.
Example:
'Select Col1 + ' ' + Col2 from Table1'
Regards,
Sathesh

List box problem

(Type your message here)

----------
From: Asp Net

Hi all,

I have list box in web form. I am populating 2 coloums in the list box. My problem is I need space between two coloumns.

lstList.Items.Add(Coloumn& " " & Coloumn) this is not working. What to do?

Thanks in advance

--------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>KL7ZpYRKnUSYXzSOYGGrFg==</Id>Hi
I come acrossed the same problem, what i did is I write the sql query which concatenate the two column and return it as a single column
Example
'Select Col1 + ' ' + Col2 from Table1

Regards
Sathesh

List Box Properties

Hai,
I am using List Box to display the Countires, States and Cities. Can some one tell me which property can determine the Index of the selected value. So that i can fill up the other list box.SelectedIndex
But come to think of it, you can also use the .SelectedValue of the combobox.
But come to think of it, you can also use the .SelectedValue of the combobox.
Thanks Buddy it helped me

List Box selected item count

I am trying to get the count in a list box for the items that are selcted.

I get Object reference not set to an instance of an object error


Dim iCnt as Integer
iCnt = myListBox.SelectedItem.Attributes.Count()

Now, this line of code works if one or more items are selected, but I need it to = 0 if none are selected.

And, if one or more is selected, it's always a 0 count.

Suggestions?

Thanks all,

ZathAs the listbox does not maintain a collection of selected items, you'll have to loop through the items collection, checking each listitem's selection property, and increment a counter for each listitem that is selected. The code you use simply counts the number of html attributes to be rendered for a selected listitem.


Dim iCnt As Integer=0
Dim li As ListItem
For Each li in myListBox.Items
If li.Selected Then iCnt += 1
Next

Check for a null reference first.
Dim intCnt As Integer = 0

If Not myListBox.SelectedItem Is Nothing Then
intCnt = myListBox.SelectedItem.Attributes.Count()
End If

You may want to verify that you are checking the right number though and refer to the above post. You are checking the HTML attributes of the selected <option> tag.
Thanks all. Now i am having trouble showing the actual item in the list....

I use myListBox.SelectedItem.Text and all I get is SELECT in the label to view it.

I need the name in the box.... I have tried every variation with no luck.

Suggetions?

Thanks again,

Zath
Nevermind, found my idiot error..... DOH

List Box scrolling

I have two listbox in a page in my website. one listbox contain report
owner name the other one contain the report name.. both the listbox
are databound.
what i wanted is that when i scroll one listbox the listbox should
also be scrolled and vice versa . please give a workaround.

thanks in advance,
ArnabIt's a pretty complex task. You need to have a very good understanding of
client-side events and programming. I doubt the effect is worth of effort.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<arnabit@.gmail.comwrote in message
news:1189416257.562684.233790@.57g2000hsv.googlegro ups.com...

Quote:

Originally Posted by

>I have two listbox in a page in my website. one listbox contain report
owner name the other one contain the report name.. both the listbox
are databound.
what i wanted is that when i scroll one listbox the listbox should
also be scrolled and vice versa . please give a workaround.
>
thanks in advance,
Arnab
>


On Sep 10, 5:58 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

It's a pretty complex task. You need to have a very good understanding of
client-side events and programming. I doubt the effect is worth of effort.
>
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>
<arna...@.gmail.comwrote in message
>
news:1189416257.562684.233790@.57g2000hsv.googlegro ups.com...
>
>
>

Quote:

Originally Posted by

I have two listbox in a page in my website. one listbox contain report
owner name the other one contain the report name.. both the listbox
are databound.
what i wanted is that when i scroll one listbox the listbox should
also be scrolled and vice versa . please give a workaround.


>

Quote:

Originally Posted by

thanks in advance,
Arnab- Hide quoted text -


>
- Show quoted text -


yaa i know it is a complex task,but i have to do this.can you tell me
a workaround ,its urgent..
On Sep 10, 2:58 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

It's a pretty complex task. You need to have a very good understanding of
client-side events and programming. I doubt the effect is worth of effort.
>
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>
<arna...@.gmail.comwrote in message
>
news:1189416257.562684.233790@.57g2000hsv.googlegro ups.com...
>
>
>

Quote:

Originally Posted by

I have two listbox in a page in my website. one listbox contain report
owner name the other one contain the report name.. both the listbox
are databound.
what i wanted is that when i scroll one listbox the listbox should
also be scrolled and vice versa . please give a workaround.


>

Quote:

Originally Posted by

thanks in advance,
Arnab- Hide quoted text -


>
- Show quoted text -


http://groups.google.com/group/micr...651d6c99933a338

List Boxes and Post Back.

Hi!, this is the problem:

I have and .aspx page that has two List Box.
The list box from the left, has a list o registers (agents in my case), and what I should do, is that when I choose one from that list, then I click on a button and the selected item, goes to the other listbox.
I mean, I have to delete that item from the first listbox and add it to the second one.

The thing is, I made some javascript for doing that. In html works perfectly, but, in aspx, not.
The problem is that every time I add an item, the page makes a submit.
I tried to add the AutoPostBack = False in the List Box, but I didn't work.

So, I thought I should use a "normal" List Box... but... how to fill that list box if it is not an ASPX Control ?

What should I do?, is there any other way to do that?

Thanks !The listbox is most likely being binded on each postback.

Try this:

If not page.ispostback then
'Load Listboxes
End If

HTH,

AspDotNetGuy
Illya,

Is this what you're trying to do?

Here's one more.
Yes!, that's what I need.

I'll check that examples.

Thanks !!!

List categories AND records at once...

Hi!

I have a SQL database with products stored in different categories.
When I click a category, I want to list all the subcategories WITH their
products.

Like this:

SubCategory 1 Name
Product 1
Product 2
Product 3

SubCategory 2 Name
Product 1
Product 2
Product 3

SubCategory 3 Name
Product 1
Product 2
Product 3

How is the "correct" way to do this in asp.net (VB.net)?
Thanks for all tips?You can easily use a Treeview webcontrol for that just BIND it to the any
datasource of your choice.
e.g Xml,DB etc..
Hope that helps
Patrick

"yvind Isaksen" <oyvind@.webressurs.no> wrote in message
news:OrLrbBm0FHA.2792@.tk2msftngp13.phx.gbl...
> Hi!
> I have a SQL database with products stored in different categories.
> When I click a category, I want to list all the subcategories WITH their
> products.
> Like this:
> SubCategory 1 Name
> Product 1
> Product 2
> Product 3
> SubCategory 2 Name
> Product 1
> Product 2
> Product 3
> SubCategory 3 Name
> Product 1
> Product 2
> Product 3
>
> How is the "correct" way to do this in asp.net (VB.net)?
> Thanks for all tips?
>

List categories AND records at once...

Hi!
I have a SQL database with products stored in different categories.
When I click a category, I want to list all the subcategories WITH their
products.
Like this:
SubCategory 1 Name
Product 1
Product 2
Product 3
SubCategory 2 Name
Product 1
Product 2
Product 3
SubCategory 3 Name
Product 1
Product 2
Product 3
How is the "correct" way to do this in asp.net (VB.net)?
Thanks for all tips?You can easily use a Treeview webcontrol for that just BIND it to the any
datasource of your choice.
e.g Xml,DB etc..
Hope that helps
Patrick
"yvind Isaksen" <oyvind@.webressurs.no> wrote in message
news:OrLrbBm0FHA.2792@.tk2msftngp13.phx.gbl...
> Hi!
> I have a SQL database with products stored in different categories.
> When I click a category, I want to list all the subcategories WITH their
> products.
> Like this:
> SubCategory 1 Name
> Product 1
> Product 2
> Product 3
> SubCategory 2 Name
> Product 1
> Product 2
> Product 3
> SubCategory 3 Name
> Product 1
> Product 2
> Product 3
>
> How is the "correct" way to do this in asp.net (VB.net)?
> Thanks for all tips?
>
>

list control

Hi to all
i have checkBox List control r this any way tro disables certain item in
this list
thanksHi,
Check for DataBound event of the checkboxlist and set the enabled property
of the individual checkbox to false.
Prakash.C
"sara" wrote:

> Hi to all
> i have checkBox List control r this any way tro disables certain item in
> this list
> thanks

list control

Hi to all
i have checkBox List control r this any way tro disables certain item in
this list
thanksHi,

Check for DataBound event of the checkboxlist and set the enabled property
of the individual checkbox to false.

Prakash.C

"sara" wrote:

> Hi to all
> i have checkBox List control r this any way tro disables certain item in
> this list
> thanks

list control and default to selected item?

Hi There,
I want to bind the value of a field from a database to make a dropdownlist
default to that value, I can't seem to get to work correctly. It just
doesn't seem work no matter what I do, could someone help me with some code?
Moe <><
lst1.SelectedItem.Value = Trim(dr("frm1value"))
<ASP:DropDownList id=lst1 name=lst1 maxlength= "40" runat=server>
<asp:ListItem Value="something">something</asp:ListItem>
<asp:ListItem Value="NO">NO</asp:ListItem>
<asp:ListItem Value="YES">YES</asp:ListItem>
</ASP:DropDownList>Hi,
I use this:
lst1.SelectedValue = myValue;
HTH,
Stefano Mostarda MCP
Rome Italy
Moe Sizlak wrote:

> Hi There,
> I want to bind the value of a field from a database to make a dropdownlist
> default to that value, I can't seem to get to work correctly. It just
> doesn't seem work no matter what I do, could someone help me with some cod
e?
>
> Moe <><
>
> lst1.SelectedItem.Value = Trim(dr("frm1value"))
>
> <ASP:DropDownList id=lst1 name=lst1 maxlength= "40" runat=server>
> <asp:ListItem Value="something">something</asp:ListItem>
> <asp:ListItem Value="NO">NO</asp:ListItem>
> <asp:ListItem Value="YES">YES</asp:ListItem>
> </ASP:DropDownList>
>

list control and default to selected item?

Hi There,

I want to bind the value of a field from a database to make a dropdownlist
default to that value, I can't seem to get to work correctly. It just
doesn't seem work no matter what I do, could someone help me with some code?

Moe <><

lst1.SelectedItem.Value = Trim(dr("frm1value"))

<ASP:DropDownList id=lst1 name=lst1 maxlength= "40" runat=server>
<asp:ListItem Value="something">something</asp:ListItem>
<asp:ListItem Value="NO">NO</asp:ListItem>
<asp:ListItem Value="YES">YES</asp:ListItem
</ASP:DropDownListHi,

I use this:
lst1.SelectedValue = myValue;

HTH,
Stefano Mostarda MCP
Rome Italy

Moe Sizlak wrote:

> Hi There,
> I want to bind the value of a field from a database to make a dropdownlist
> default to that value, I can't seem to get to work correctly. It just
> doesn't seem work no matter what I do, could someone help me with some code?
>
> Moe <><
>
> lst1.SelectedItem.Value = Trim(dr("frm1value"))
>
> <ASP:DropDownList id=lst1 name=lst1 maxlength= "40" runat=server>
> <asp:ListItem Value="something">something</asp:ListItem>
> <asp:ListItem Value="NO">NO</asp:ListItem>
> <asp:ListItem Value="YES">YES</asp:ListItem>
> </ASP:DropDownList>
>

List Controls

Hello All,

I have a List Box and for that list box there are already some values defined.

first time when the user comes to webpage i can able to show the list to the user. once the user selects some values and stores in database in someother table. when again he visits the page i need to show them as selected and allow him to modify the current selections.

how can i achieve that.

General Problem

See if this helps:http://www.mikesdotnetting.com/Article.aspx?ArticleID=53. It features checkboxlists, but the principal behind it is identical.

List controll + XML

Can I use a list control with an XML data source?Yes,

two ways:

1) Query the nodes from XML data source and create ListItems manually (this applies to DropDownList,ListBox and such)

2) Load XML into DataSet and bind it to the control (applies to all controls, but there are slight restrictions to the format of the XML)
Can I see an example??

Thanks!

List Control, multiple choise from the code

Hello!

Please, could anyone tell, is it possible to set multiple items to be
selected in list control in the code? For example when the web form is loaded
three items of 5 are selected in list control already? Now I manage to set
only one item to be selected during page load, but there is need to multiple
items could be selected for the user. I appreciate very much your help!

Thanks.

PavelPeter wrote:

> Hello!
> Please, could anyone tell, is it possible to set multiple items to be
> selected in list control in the code? For example when the web form is loaded
> three items of 5 are selected in list control already? Now I manage to set
> only one item to be selected during page load, but there is need to multiple
> items could be selected for the user. I appreciate very much your help!
> Thanks.
> Pavel
>
Yes, try this statement before you start selecting the items

'Set Selection mode as Multiple
[YourListBoxID].SelectionMode = ListSelectionMode.Multiple

Full Page Example:
------
<%@. PAGE language="VB" runat="server" %
<SCRIPT language="vb" runat="server"
Sub Page_Load(Source as Object, E As EventArgs)

'Add Items To List
lbxList.Items.Add("Item 1")
lbxList.Items.Add("Item 2")
lbxList.Items.Add("Item 3")
lbxList.Items.Add("Item 4")
lbxList.Items.Add("Item 5")
lbxList.Items.Add("Item 6")
lbxList.Items.Add("Item 7")
lbxList.Items.Add("Item 8")
lbxList.Items.Add("Item 9")
lbxList.Items.Add("Item 10")

lbxList.Rows = 10
'Set Selection mode as Multiple
lbxList.SelectionMode = ListSelectionMode.Multiple

Dim litmItem as ListItem

' Select every third list item
Dim i As Integer = 0

For Each litmItem In lbxList.Items
If (i + 1) MOD 3 = 0 Then
litmItem.Selected = True
End If
i += 1
Next

End Sub
</SCRIPT
<HTML>
<HEAD>
<TITLE>Multi-Selected ListBox</TITLE>
</HEAD>
<BODY>
<FORM id="theForm" runat="server">
<ASP:listbox id="lbxList" runat="server"/
</FORM>
</BODY>
</HTML
--
Change "seven" to a digit to email.
Hi

jus try this,

lstdropdown.SelectedIndex = -1;
for (int i=0; i<Datatable.Rows.Count;i++)

lstdropdown.Items.FindByValue(Datatable.Rows[i]["ColumnName"].ToString()).Se
lected=true;

Regards,
Kannan

"Peter" <Peter@.discussions.microsoft.com> wrote in message
news:DBA09527-5A47-4B83-9DCD-0889F6CF4B92@.microsoft.com...
> Hello!
> Please, could anyone tell, is it possible to set multiple items to be
> selected in list control in the code? For example when the web form is
loaded
> three items of 5 are selected in list control already? Now I manage to set
> only one item to be selected during page load, but there is need to
multiple
> items could be selected for the user. I appreciate very much your help!
> Thanks.
> Pavel

list controls and the CustomValidator

I'm using a CustomValidator within a datagrid control. I'd like to
get the index of the item (i.e. row of the datagrid) when the
validator is fired and use this number in my custom function. Can
this be done?(Following is an answer I received, in a different post.)
Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum
'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender
'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent
'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent
'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)

list controls and the CustomValidator

I'm using a CustomValidator within a datagrid control. I'd like to
get the index of the item (i.e. row of the datagrid) when the
validator is fired and use this number in my custom function. Can
this be done?(Following is an answer I received, in a different post.)

Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum

'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender

'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent

'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent

'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)

list Crystal pdf reports from folder

can anyone point me to any articles on how i can read back .pdf files from a folder called Reports on my server, an then list them on my Webpage, so that when you click them they open up the .pdf file in a new browser window??

Thanks in advance!

If you mean how can you list all the reports in a folder and then hyperlink to it, then here is a solution.
' Get file informationDim parentDirAs DirectoryInfoDim childFilesAs FileInfo()Try parentDir =New DirectoryInfo(Server.MapPath(folderPath)) childFiles = parentDir.GetFiles()Catch excAs Exception StatusMessage.Text = exc.Message StatusMessage.Visible =TrueEnd TryDim childFileAs FileInfoFor Each childFileIn childFilesDim linkItemAs New HyperLink()With linkItem .Text = childFile.Name .Target ="_blank" .NavigateUrl ="fullpathOfFile"End WithNext

that sounds about right for what i am trying to do, but im pretty crap at vb.net, in fact its nonexistant to say the least. anyway you could translate it to c# please? is the below correct:

DirectoryInfo parentDir = new DirectoryInfo();
FileInfo childFiles = new FileInfo();

try
{
parentDir = Server.MapPath("C:\Inetpub\wwwroot\Database\Reports\");
childFiles = parentDir.GetFiles();
}
catch (ex As Exception)
{
textBox1.text = ex.Message();
textBox1.visible = true;
}

FileInfo childFile = new FileInfo();
foreach(childFile in childFiles)
{
HyperLink linkItem = new HyperLink();
linkItem.text = childFile.Name;
linkItem.Targer = "_blank";
linkItem.NavigateUrl = "####"
}
Next

not sure if this is correct or not. any help appreciated. thanks!


FileInfo childFiles = new FileInfo();

Should be:

FileInfo[] childFiles;

//because this is an array of files and not a single file

Otherwise everything looks fine. Also the argument passed for MapPath method is the virtual path and not the actual path. This method takes in the virtual path and gives you the actual path. If you want to specify a directory then use DirectoryInfo(string path). Try out your code, if you run into any problems reply to the post.

Best of luck.


Thanks for replying. get the following error:

Type and identifier are both required in a foreach statement

my code is below:

private

void LnkBtn_ViewRpt_Click(object sender, System.EventArgs e)
{
//this will show all the reports presently in the system by reading
//through all of the pdf report files in the folder on the drive.
System.IO.DirectoryInfo parentDir;
System.IO.FileInfo[] childFiles;
try
{
parentDir =new System.IO.DirectoryInfo("C:\\Inetpub\\wwwroot\\CalendarBCP\\Reports_PDF\\");
childFiles = parentDir.GetFiles();
}
catch (Exception ex)
{
Label6.Text = ex.Message;
}
System.IO.FileInfo[] childFile;
foreach(childFilein childFiles)
{
HyperLink linkItem =new HyperLink();
linkItem.Text = childFile.Name;
linkItem.Target = "_blank";
linkItem.NavigateUrl = "#";
}
}

Any help is greatly appreciated. Thanks!


I have found another way:

private

void LnkBtn_ViewRpt_Click(object sender, System.EventArgs e)
{
//this will show all the reports presently in the system by reading
//through all of the pdf report files in the folder on the drive.
string location = "C:\\Inetpub\\wwwroot\\CalendarBCP\\Reports_PDF\\";
System.IO.DirectoryInfo dir =new System.IO.DirectoryInfo(location);
foreach (System.IO.FileInfo fin dir.GetFiles())
{
//load items
//HyperLink linkItem = new HyperLink();
//linkItem.Text = f.Name;
//linkItem.Target = "_blank";
//linkItem.NavigateUrl = "#";
ListBox1.Items.Add(f.Name);
//ListBox1.Items.Add(linkItem);
}
}

I can get it to display the items from the folder into a listbox, but i dont know how to add a linked item to a listbox. im not sure if this is possible or not. ideally I already have datagrid on the form, is it not possible to add the items to the datagrid and the somehow create a link to each document to be opened in a new browser window.

Any help appreciated. Thanks in advance!


Glad you figured out a solution. Unfortunately you cannot have a hyperlink as a ListItem in a ListBox (unless you are going to use third party items. A good example ishttp://www.easylistbox.com by Peter Brunone. I have never used it. You might get more products, if you search the control gallery of this site as well as search in google).

Other options are to use any of the other data-presentation controls and use the template to achieve what you want or create a place holder (panel, placeholder, table etc) and create the hyperlinks and add to the control's collection of the container.

Hope this answers your questions.

list countries along with timezones

hi,

i need to include the functionality which lists out all the country names and time zones.

can any body suggest me where can i find this.

its urgent

You will need to either maintain your own database or crawl the information from a reliable site. Since the governments' daylight saving time are altered from time to time, there are few websites dedicated for the latest definitions on time zones:

http://home.tiscali.nl/~t876506/Multizones.html

http://home.tiscali.nl/~t876506/TZworld.html

List controls....

Hi everyone,

I have a page with bunch of list controls with postback enabled.. after the selection is made, postback event is fired but the selected values don't stay selected after the postback..

the control randomly selects a different value from the list.. why?

I have viewstate enabled for page/app/control..

PS: I am not loading/binding the control values on page load event.

here is my source...


<td valign="top" class="LightGray">
<asp:RadioButtonList id="lstmarried1" runat="server" CssClass="form" CellSpacing="1" RepeatColumns="2"CellPadding="1" AutoPostBack="True"
<asp:ListItem Value="2" Selected="True">Single</asp:ListItem>
<asp:ListItem Value="1">Engaged</asp:ListItem>
<asp:ListItem Value="1">Married</asp:ListItem>
<asp:ListItem Value="2">Divorced</asp:ListItem>
<asp:ListItem Value="2">Separated</asp:ListItem>
</asp:RadioButtonList></td>
</tr

CODE Behind..


Private Sub lstmarried1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstmarried1.SelectedIndexChanged

If lstmarried1.SelectedItem.Value = 1 Then
p1.Visible = True
p2.Visible = True
Else
p1.Visible = False
p2.Visible = False
End If
End Sub

Show us the code in the Page_Load function plz.
My guess is that you use the same values in the listitem object for multiple items. Ex : Single, Divorced and Seperated = 2

I suppose when the page is post back, you get one of these 3 results checked instead the one you selected first.

Try changing the values to unique values, I think that will fix the problem, of course you will need to change your validation "If lstmarried1.SelectedItem.Value = 1 Then" to something else.

A suggestion :


<asp:ListItem Value="3" Selected="True">Single</asp:ListItem
<asp:ListItem Value="1">Engaged</asp:ListItem
<asp:ListItem Value="2">Married</asp:ListItem
<asp:ListItem Value="4">Divorced</asp:ListItem
<asp:ListItem Value="5">Separated</asp:ListItem

And change the code behind for something like that


If lstmarried1.SelectedItem.Value > 2 Then

p1.Visible = True

p2.Visible = True

Else

p1.Visible = False

p2.Visible = False

End If

Or you can remove the value field and it will get the text value instead the number. You can then switch through the choices of "lstmarried1.SelectedItem.Value"
Hi hexenjag,

Thanks mate you were spot on..!

I just changed the value of the list items and it just worked fine. It funny how Asp.NET is just depending on the value param or the control

Cheers!

List Controls on Datagrid will not show Selection after Postback

Hi,

I have an "interesting" problem with UserControls in a datagrid and I'm
desperate for your help as I work alone and have no-one else to ask. It
is quite complicated but I'll try to keep it to a simple example ...

FormQuestionAnswer.ascx
--------
I have a user Control that displays a question (from a questionnaire)
and its answer (as previously selected by a user). The question has a
list of possible answers in a CheckBoxList control. There is also an
"Other" option allowing the user to specify an answer as text. Note:
this is supposed to be a read-only control simply for display purposes,
I am not requiring any user input here.

QuestionnaireAnswerList.ascx
---------
The parent UserControl contains a datagrid based on a particular
questionnaire with answers given by a particular user. Each row in the
datagrid displays an instance of the FormQuestionAnswer.ascx
UserControl, one for each question in the questionnaire.

When I first load the page the answers are all selected correctly. Any
text answers are displayed in labels.

However if, for any reason, the page is posted back (e.g. the
questionnaire is changed or the user is changed) then the list controls
no longer display any selections. Any text answers do still come
through as labels. Please note: this is NOT a ViewState issue as I am
loading up new controls afresh with new answers each time and the
selections are made according to data from my database.

I have been through the code a hundred times and traced the stack. Each
time the followng happens: the datagrid is bound, the
FormQuestionAnswer controls are created, the list controls are
databound and then last of all the selections are made. Nothing happens
to the controls after the selections are made (I was looking for a
subsequent DataBind() that would account for the selections being lost
but it doesn't happen).

I cannot find any significant difference in the stack trace when the
page is posted back which would account for this problem.

Does anyone have any ideas as to why this might be happening? Any
insight much appreciated.

Thanks in advance.

JoanneHi Joanne, sorry i'm a bit distracted by the news... but.. make sure all your
controls are loaded before the page loads viewstate and post data. This is a
particular issue if you are dynamically loading controls into the page. e.g
create your controls in page.init event HTH jd

"Joanne" wrote:

> Hi,
> I have an "interesting" problem with UserControls in a datagrid and I'm
> desperate for your help as I work alone and have no-one else to ask. It
> is quite complicated but I'll try to keep it to a simple example ...
> FormQuestionAnswer.ascx
> --------
> I have a user Control that displays a question (from a questionnaire)
> and its answer (as previously selected by a user). The question has a
> list of possible answers in a CheckBoxList control. There is also an
> "Other" option allowing the user to specify an answer as text. Note:
> this is supposed to be a read-only control simply for display purposes,
> I am not requiring any user input here.
> QuestionnaireAnswerList.ascx
> ---------
> The parent UserControl contains a datagrid based on a particular
> questionnaire with answers given by a particular user. Each row in the
> datagrid displays an instance of the FormQuestionAnswer.ascx
> UserControl, one for each question in the questionnaire.
> When I first load the page the answers are all selected correctly. Any
> text answers are displayed in labels.
> However if, for any reason, the page is posted back (e.g. the
> questionnaire is changed or the user is changed) then the list controls
> no longer display any selections. Any text answers do still come
> through as labels. Please note: this is NOT a ViewState issue as I am
> loading up new controls afresh with new answers each time and the
> selections are made according to data from my database.
> I have been through the code a hundred times and traced the stack. Each
> time the followng happens: the datagrid is bound, the
> FormQuestionAnswer controls are created, the list controls are
> databound and then last of all the selections are made. Nothing happens
> to the controls after the selections are made (I was looking for a
> subsequent DataBind() that would account for the selections being lost
> but it doesn't happen).
> I cannot find any significant difference in the stack trace when the
> page is posted back which would account for this problem.
> Does anyone have any ideas as to why this might be happening? Any
> insight much appreciated.
> Thanks in advance.
> Joanne
>
Hi,

Thanks for the reply. I'm not quite sure if you are saying it is good
or bad to create controls in the page.init event. In any case that is
not what I've been doing so far.

In the FormQuestionAnswer.ascx usercontrol, all the standard controls I
could possibly need are already declared and visible on the page. At
page_load I hide them all, then find out what sort of answer is
required and make visible the appropriate answer control (e.g. the
CheckBoxList), then select the appropriate answers ( e.g. select some
of the checkboxes). I have set public properties QuestionID and UserID
for the UserControl to determine the question and answer required.

The UserControl gets created when the datagrid in the parent page is
databound. The html for the datagrid looks something like this ...

QuestionnaireAnswerList.ascx
---------
<asp:datagrid id="dg" runat="server" >
<Columns>
<asp:TemplateColumn HeaderText="">
<ItemTemplate>
<uc1:FormQuestionAnswer id="ctlFormQuestionAnswer1" runat="server"
UserID='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem ,
"UserID")) %>' QuestionID='<%#
Convert.ToInt32(DataBinder.Eval(Container.DataItem , "QuestionID")) %>'>
</uc1:FormQuestionAnswer>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid
In the FormQuestionAnswer.ascx usercontrol when the public property,
QuestionID, is set, the call to make the appropriate selections is
made. The c# code looks something like this ...

FormQuestionAnswer.ascx
--------
//passed in
public int QuestionID
{
get
{
return mintQuestionID;
}
set
{
mintQuestionID = value;
//Whenever QuestionID changed, set up new question
SetUpNewQuestion();
}
}

public void SetUpNewQuestion()
{
//First set all the controls to hide
HideQuestionControls();

//What Answer type do we want?
switch(CurrentFormQuestion.AnswerTypeID)
{
case lkAnswerType.gintCurrencyID:
{
SetUpCurrencyAnswer(map);
break;
}
// more cases here ...
case lkAnswerType.gintListID:
{
SetUpCheckBoxListAnswer();
break;
}
}

--***--
SetUpCheckBoxListAnswer() binds the possible answers to the
checkBoxList and makes it visible. The answers given by the user are
then selected.

Note: The Page_Load() method of FormQuestionAnswer.ascx also calls
SetUpNewQuestion() the first time it is run.

FormQuestionAnswer.ascx
--------
private void Page_Load(object sender, System.EventArgs e)
{
//Clear the SessionObject vars
if(!IsPostBack)
{
//Initially, set up the question
//next time, wait for event to be fired
SetUpNewQuestion();
}
}

--***--
This means that SetUpNewQuestion() gets called at least twice the first
time, but when I took it away, it didn't work. My investigations also
showed that if I removed the if(!IsPostBack) condition and allowed the
SetUpNewQuestion() event to be called again on postback, it still
resulted in the same problem - list items not being selected.

Driving me mad, but thanks very much for any help!
Joanne

List departments horizontal in ASP.NET 2.0

Hello, all,

I'm developing a site in which I want my departments (Accounting, IT, Sales, etc.) to be at the top of the page going horizontal across the top of page (in the header) When user selects one of departments, another control, this one vertical on left side will list products these departments has.

I have the departments in a SQL DB. My question is, what ASP.NET 2.0 control should I use to display these (Accounting, IT, Sales) going horizontal and also make them hyperlinks?

Thanks,

StrickYou can make use of DataList as you want Horzontal Display of main Dept.
you can also make master page that contain Dept list and then in content page can show sub dept.
And for the Sub Dept. U can make use of Repeater.
The Menu control.

List Directories in ListBox

I am not very sure whether I should have continued with my earlier
thread or started a new thread whose subject matter was somewhat
similar to the subject matter in this thread. Anyway after much
deliberation, I decided to start a new thread. So here it is. Pardon me
if I should have continued with my earlier thread instead of starting
this new thread.
A ListBox lists all the directories & files existing in a directory on
the server. Assume that one of the directories is named the following:
"IHIS IS MY FOLDER"
The double quotes have been added just to show where the directory name
ends; it's not a part of the text.
But the ListBox displays the name of this directory as
"IHIS IS MY FOLDER"
i.e. the ListBox replaces all the whitespaces between words with a
single whitespace.
How do I make the ListBox retain the whitespaces present in the name of
the directory so that the directory listed in the ListBox displays
EXACTLY the same name as the name of the directory which exists in the
hard drive of the server? In other words, how do I make the ListBox
list the above directory as
"IHIS IS MY FOLDER"
& not as
"IHIS IS MY FOLDER"<rn5a@.rediffmail.com> wrote in message
news:1168121711.971527.41870@.q40g2000cwq.googlegroups.com...

>I am not very sure whether I should have continued with my earlier
> thread or started a new thread whose subject matter was somewhat
> similar to the subject matter in this thread. Anyway after much
> deliberation, I decided to start a new thread. So here it is. Pardon me
> if I should have continued with my earlier thread instead of starting
> this new thread.
> A ListBox lists all the directories & files existing in a directory on
> the server. Assume that one of the directories is named the following:
> "IHIS IS MY FOLDER"
> The double quotes have been added just to show where the directory name
> ends; it's not a part of the text.
> But the ListBox displays the name of this directory as
> "IHIS IS MY FOLDER"
> i.e. the ListBox replaces all the whitespaces between words with a
> single whitespace.
> How do I make the ListBox retain the whitespaces present in the name of
> the directory so that the directory listed in the ListBox displays
> EXACTLY the same name as the name of the directory which exists in the
> hard drive of the server? In other words, how do I make the ListBox
> list the above directory as
> "IHIS IS MY FOLDER"
> & not as
> "IHIS IS MY FOLDER"
It's standard browser / HTML behaviour to ignore double spaces.
Try replacing each space with - I haven't tried this, though, so I
can't guarantee it'll work...
Mark, this is how I am populating the ListBox with directories & files:
Sub Page_Load(....)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath("Folder1"))
lstFilesDirs.DataSource = dInfo.GetFileSystemInfos
lstFilesDirs.DataBind()
End Sub
Now how do I use the Replace string function while setting the
DataSource of the ListBox so that whitespaces get replaced with ?
Moreover, I would like to add more information about each directory &
file listed in the ListBox. For e.g. if an item happens to be a
directory, I would like to add a string, say, <DIR> on the same line
where the directory is listed in the ListBox. If an item happens to be
a file, I would like to add the size of the file along with the date &
time on which the file was created on the same line where the file is
listed in the ListBox. The ListBox should look something like this:
Folder1 <DIR>
Folder2 <DIR>
File1.aspx 22346 31/12/2006 5:34:11 AM
File2.aspx 7634 03/01/2007 8:24:52 PM
File3.aspx 2903 05/01/2007 1:16:33 PM
Any idea how do I append the additional info for each directory & file
on the same row where the directory & the file is listed respectively
in the ListBox?
I would like to request everyone to please view this post using the
fixed font. I guess that will give a better picture of how I want the
ListBox to look like with the additional info for each directory &
file.
I guess I am asking for too many favors. Sorry for the same.
Mark Rae wrote:
> <rn5a@.rediffmail.com> wrote in message
> news:1168121711.971527.41870@.q40g2000cwq.googlegroups.com...
>
> It's standard browser / HTML behaviour to ignore double spaces.
> Try replacing each space with - I haven't tried this, though, so I
> can't guarantee it'll work...
<rn5a@.rediffmail.com> wrote in message
news:1168125433.786895.108050@.42g2000cwt.googlegroups.com...

> Mark, this is how I am populating the ListBox with directories & files:
> Sub Page_Load(....)
> Dim dInfo As DirectoryInfo
> dInfo = New DirectoryInfo(Server.MapPath("Folder1"))
> lstFilesDirs.DataSource = dInfo.GetFileSystemInfos
> lstFilesDirs.DataBind()
> End Sub
> Now how do I use the Replace string function while setting the
> DataSource of the ListBox so that whitespaces get replaced with ?
You can't - you'll need to add the items individually through code. That
will allow you to do any sort of string manipulation you like
http://community.strongcoders.com/f...hread/1477.aspx

List Directories in ListBox

I am not very sure whether I should have continued with my earlier
thread or started a new thread whose subject matter was somewhat
similar to the subject matter in this thread. Anyway after much
deliberation, I decided to start a new thread. So here it is. Pardon me
if I should have continued with my earlier thread instead of starting
this new thread.

A ListBox lists all the directories & files existing in a directory on
the server. Assume that one of the directories is named the following:

"IHIS IS MY FOLDER"

The double quotes have been added just to show where the directory name
ends; it's not a part of the text.

But the ListBox displays the name of this directory as

"IHIS IS MY FOLDER"

i.e. the ListBox replaces all the whitespaces between words with a
single whitespace.

How do I make the ListBox retain the whitespaces present in the name of
the directory so that the directory listed in the ListBox displays
EXACTLY the same name as the name of the directory which exists in the
hard drive of the server? In other words, how do I make the ListBox
list the above directory as

"IHIS IS MY FOLDER"

& not as

"IHIS IS MY FOLDER"<rn5a@.rediffmail.comwrote in message
news:1168121711.971527.41870@.q40g2000cwq.googlegro ups.com...

Quote:

Originally Posted by

>I am not very sure whether I should have continued with my earlier
thread or started a new thread whose subject matter was somewhat
similar to the subject matter in this thread. Anyway after much
deliberation, I decided to start a new thread. So here it is. Pardon me
if I should have continued with my earlier thread instead of starting
this new thread.
>
A ListBox lists all the directories & files existing in a directory on
the server. Assume that one of the directories is named the following:
>
"IHIS IS MY FOLDER"
>
The double quotes have been added just to show where the directory name
ends; it's not a part of the text.
>
But the ListBox displays the name of this directory as
>
"IHIS IS MY FOLDER"
>
i.e. the ListBox replaces all the whitespaces between words with a
single whitespace.
>
How do I make the ListBox retain the whitespaces present in the name of
the directory so that the directory listed in the ListBox displays
EXACTLY the same name as the name of the directory which exists in the
hard drive of the server? In other words, how do I make the ListBox
list the above directory as
>
"IHIS IS MY FOLDER"
>
& not as
>
"IHIS IS MY FOLDER"


It's standard browser / HTML behaviour to ignore double spaces.

Try replacing each space with - I haven't tried this, though, so I
can't guarantee it'll work...
Mark, this is how I am populating the ListBox with directories & files:

Sub Page_Load(....)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath("Folder1"))
lstFilesDirs.DataSource = dInfo.GetFileSystemInfos
lstFilesDirs.DataBind()
End Sub

Now how do I use the Replace string function while setting the
DataSource of the ListBox so that whitespaces get replaced with ?

Moreover, I would like to add more information about each directory &
file listed in the ListBox. For e.g. if an item happens to be a
directory, I would like to add a string, say, <DIRon the same line
where the directory is listed in the ListBox. If an item happens to be
a file, I would like to add the size of the file along with the date &
time on which the file was created on the same line where the file is
listed in the ListBox. The ListBox should look something like this:

Folder1 <DIR>
Folder2 <DIR>
File1.aspx 22346 31/12/2006 5:34:11 AM
File2.aspx 7634 03/01/2007 8:24:52 PM
File3.aspx 2903 05/01/2007 1:16:33 PM

Any idea how do I append the additional info for each directory & file
on the same row where the directory & the file is listed respectively
in the ListBox?

I would like to request everyone to please view this post using the
fixed font. I guess that will give a better picture of how I want the
ListBox to look like with the additional info for each directory &
file.

I guess I am asking for too many favors. Sorry for the same.

Mark Rae wrote:

Quote:

Originally Posted by

<rn5a@.rediffmail.comwrote in message
news:1168121711.971527.41870@.q40g2000cwq.googlegro ups.com...
>

Quote:

Originally Posted by

I am not very sure whether I should have continued with my earlier
thread or started a new thread whose subject matter was somewhat
similar to the subject matter in this thread. Anyway after much
deliberation, I decided to start a new thread. So here it is. Pardon me
if I should have continued with my earlier thread instead of starting
this new thread.

A ListBox lists all the directories & files existing in a directory on
the server. Assume that one of the directories is named the following:

"IHIS IS MY FOLDER"

The double quotes have been added just to show where the directory name
ends; it's not a part of the text.

But the ListBox displays the name of this directory as

"IHIS IS MY FOLDER"

i.e. the ListBox replaces all the whitespaces between words with a
single whitespace.

How do I make the ListBox retain the whitespaces present in the name of
the directory so that the directory listed in the ListBox displays
EXACTLY the same name as the name of the directory which exists in the
hard drive of the server? In other words, how do I make the ListBox
list the above directory as

"IHIS IS MY FOLDER"

& not as

"IHIS IS MY FOLDER"


>
It's standard browser / HTML behaviour to ignore double spaces.
>
Try replacing each space with - I haven't tried this, though, so I
can't guarantee it'll work...


<rn5a@.rediffmail.comwrote in message
news:1168125433.786895.108050@.42g2000cwt.googlegro ups.com...

Quote:

Originally Posted by

Mark, this is how I am populating the ListBox with directories & files:
>
Sub Page_Load(....)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath("Folder1"))
lstFilesDirs.DataSource = dInfo.GetFileSystemInfos
lstFilesDirs.DataBind()
End Sub
>
Now how do I use the Replace string function while setting the
DataSource of the ListBox so that whitespaces get replaced with ?


You can't - you'll need to add the items individually through code. That
will allow you to do any sort of string manipulation you like

http://community.strongcoders.com/f...hread/1477.aspx