Saturday, March 31, 2012

Setting Image as background

Hi,

Im trying to set an image as the background on my webpage but how do i set it up so it doesnt become tiled, i want it to strertch and fill the screen ! cheersTo stop the image from tiling you can insert the following between the <HEAD> elements of your page

<style type="text/css">
<!--
body {background-image: url(your_image_folder/your_image.jpg); background-repeat: no-repeat}
-->
</style>

This will not stretch the image though. The is no way to do this in standard HTML. An alternative is to create an enlarged image and use that as your background, or you can try using an Image control which spans the entire page and then placing all other controls on top of it, but this should be avoided if possible because it can cause headaches if a control is behind the image and it is forgotten.

hope this helps,
sivilian

setting IIS authentication methods in web.config

Does anyone know if it is possible to set IIS authentication methods
(e.g. anonymous access, basic authentication, IWA, etc) in the
web.config file?

For example, I want to remove Anonymous Access for an entire directory
in my ASP .NET project and only use Integrated Windows Authentication.

Is there some way I can configure that in the web.config file or do I
need my Infrastructure guys to make that change in IIS?

JeremyYou can't change the IIS settings, but you can set the ASP.Net forms
authentication settings for specific directories and such to use Windows
permissions instead. Check out the forms authentication portion of the .net
framework help docs.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

<jeremy.stitt@.gmail.com> wrote in message
news:1118257534.495821.291310@.g47g2000cwa.googlegr oups.com...
> Does anyone know if it is possible to set IIS authentication methods
> (e.g. anonymous access, basic authentication, IWA, etc) in the
> web.config file?
> For example, I want to remove Anonymous Access for an entire directory
> in my ASP .NET project and only use Integrated Windows Authentication.
> Is there some way I can configure that in the web.config file or do I
> need my Infrastructure guys to make that change in IIS?
> Jeremy

setting ImageUrl for images through code not working

Dear world,
I have an IMAGE control placed on my .aspx page with its ImageUrl
property not set.
In my code, i am setting it equal to something using the following
statement
img.ImageUrl = Server.MapPath ("usedIcons/AssignAccess/" +
reader["sImage"].ToString ());
where reader as the name implies is a DataReader object reading a value
from the database.
The funny part is, when I run the code in LOCALHOST mode, it works
perfectly. But it was an embarassing experience for me, when I finally
deployed on server and asked my client to try from their remote client
machine. THE IMAGE DID NOT LOAD. All such images had the usual "X" on
them.
Why does it work on LOCALHOST, but not when viewing from a remote
client?
My doubts in case it helps you to help me:
1. Is Server.MapPath the right way to do it?
2. Is there any place in the document where this code should be kept?
3. I will be shocked if the answer to this one is "yes". "IS THE
BROWSWER LOOKING FOR THE IMAGE ON THE CLIENT MACHINE RATHER THAN ON
SERVER?"
Thanks a lot...
Michelle StoneYES, the client machine is looking for the file locally, not on your server.
Server.MapPath is for working with local paths.
In this case you want a URL that points to the image, not a local path.
To verify this you can view the HTML that is sent to the browser.
(Right click on IE web page and choose View Source.)
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
<mich_stone@.yahoo.com> wrote in message
news:1102575746.137794.265530@.f14g2000cwb.googlegroups.com...
> Dear world,
> I have an IMAGE control placed on my .aspx page with its ImageUrl
> property not set.
> In my code, i am setting it equal to something using the following
> statement
> img.ImageUrl = Server.MapPath ("usedIcons/AssignAccess/" +
> reader["sImage"].ToString ());
> where reader as the name implies is a DataReader object reading a value
> from the database.
> The funny part is, when I run the code in LOCALHOST mode, it works
> perfectly. But it was an embarassing experience for me, when I finally
> deployed on server and asked my client to try from their remote client
> machine. THE IMAGE DID NOT LOAD. All such images had the usual "X" on
> them.
> Why does it work on LOCALHOST, but not when viewing from a remote
> client?
> My doubts in case it helps you to help me:
> 1. Is Server.MapPath the right way to do it?
> 2. Is there any place in the document where this code should be kept?
> 3. I will be shocked if the answer to this one is "yes". "IS THE
> BROWSWER LOOKING FOR THE IMAGE ON THE CLIENT MACHINE RATHER THAN ON
> SERVER?"
> Thanks a lot...
> Michelle Stone
>
When you view the images from the remote host right click on the
missing image (where the "X" is) and select properties. This will tell
you where the path is getting resolved to... From this information
you will probably see the error...
More importantly you should not be using MapPath at all to set the
ImageUrl property. MapPath is used to find a Physical Path on the hard
drive for a file... That means the path is resolving to something like
c:\inetpub\wwwroot\myweb\images....etc... not good!
Just set the ImageUrl like:
img.ImageUrl = "usedIcons/AssignAccess" + reader["sImage"].ToString ());

setting ImageUrl for images through code not working

Dear world,

I have an IMAGE control placed on my .aspx page with its ImageUrl
property not set.

In my code, i am setting it equal to something using the following
statement

img.ImageUrl = Server.MapPath ("usedIcons/AssignAccess/" +
reader["sImage"].ToString ());

where reader as the name implies is a DataReader object reading a value
from the database.

The funny part is, when I run the code in LOCALHOST mode, it works
perfectly. But it was an embarassing experience for me, when I finally
deployed on server and asked my client to try from their remote client
machine. THE IMAGE DID NOT LOAD. All such images had the usual "X" on
them.

Why does it work on LOCALHOST, but not when viewing from a remote
client?

My doubts in case it helps you to help me:
1. Is Server.MapPath the right way to do it?
2. Is there any place in the document where this code should be kept?
3. I will be shocked if the answer to this one is "yes". "IS THE
BROWSWER LOOKING FOR THE IMAGE ON THE CLIENT MACHINE RATHER THAN ON
SERVER?"

Thanks a lot...

Michelle StoneYES, the client machine is looking for the file locally, not on your server.
Server.MapPath is for working with local paths.
In this case you want a URL that points to the image, not a local path.

To verify this you can view the HTML that is sent to the browser.
(Right click on IE web page and choose View Source.)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

<mich_stone@.yahoo.com> wrote in message
news:1102575746.137794.265530@.f14g2000cwb.googlegr oups.com...
> Dear world,
> I have an IMAGE control placed on my .aspx page with its ImageUrl
> property not set.
> In my code, i am setting it equal to something using the following
> statement
> img.ImageUrl = Server.MapPath ("usedIcons/AssignAccess/" +
> reader["sImage"].ToString ());
> where reader as the name implies is a DataReader object reading a value
> from the database.
> The funny part is, when I run the code in LOCALHOST mode, it works
> perfectly. But it was an embarassing experience for me, when I finally
> deployed on server and asked my client to try from their remote client
> machine. THE IMAGE DID NOT LOAD. All such images had the usual "X" on
> them.
> Why does it work on LOCALHOST, but not when viewing from a remote
> client?
> My doubts in case it helps you to help me:
> 1. Is Server.MapPath the right way to do it?
> 2. Is there any place in the document where this code should be kept?
> 3. I will be shocked if the answer to this one is "yes". "IS THE
> BROWSWER LOOKING FOR THE IMAGE ON THE CLIENT MACHINE RATHER THAN ON
> SERVER?"
> Thanks a lot...
> Michelle Stone
When you view the images from the remote host right click on the
missing image (where the "X" is) and select properties. This will tell
you where the path is getting resolved to... From this information
you will probably see the error...

More importantly you should not be using MapPath at all to set the
ImageUrl property. MapPath is used to find a Physical Path on the hard
drive for a file... That means the path is resolving to something like
c:\inetpub\wwwroot\myweb\images....etc... not good!

Just set the ImageUrl like:
img.ImageUrl = "usedIcons/AssignAccess" + reader["sImage"].ToString ());

Setting ImageUrl for Image on Master Page

Hi,

I have a master page which includes a header, a navigation system and a ContentPlacHolder.

In the header is an <asp:Image> which I have exposed via a property, and I need to (optionally) set it's ImageUrl per each content page that uses the master.

So far, just to learn the concept, I've successfully set the ImageUrl via code in a few content pages:

this.Master.MasterImage.ImageUrl ="images/image01.jpg"

Eventually, I'll have many pages, so I would like to automate this process. Maybe look up the image in a database or something ...

Is there a way/place (maybe some global event or something?) to place some code (I can make the code) that runs every time each content page is loaded? Also, can I specify that itonly happens if the content page has a specific master page?

I'm just trying to make it so that others wont have to add the above line of code to each new content page that is made in the future. If others are adding content pages, they don't need to access the code-behind. All they will need to do is define the url in a database or something.

I'm using the ASP 2 beta, so maybe it has something new?

Thanks!

Hello.
well, i was tempted to suggest the creation of a custom master page that would add that line on the load event of the page but if you try that you'll have a dependency problem.
here's my suggestion:
create a new aspx file which doesn't have any controls on it. comething like this:

<%@.PageLanguage="C#" %>
<%@.ReferenceControl="~/MasterPage.master" %>
<scriptrunat="server">
protectedoverridevoid OnLoad(EventArgs args )
{
if (this.Master !=null )
{
if (this.Masteris ASP.MasterPage_master )
{
//your code here
}
}
}
</script>

Then you could build all your pages by inherting from that 1st aspx page. something like this:

<%@.ReferencePage="~/Default3.aspx" %>
<%@.PageLanguage="C#"Inherits="ASP.Default3_aspx"MasterPageFile="~/MasterPage.master"Debug="true" %>
<asp:Contentrunat="server"ContentPlaceHolderID="ContentPlaceHolder1"ID="p">
safsdf
</asp:Content>

This is the best I can think of. You still have to add the @.Reference tag to all your pages but you won't have to write any code for setting the master property.

Setting initial focus to a textbox when the page loads.

I can do this by using:
document.Form1.MyTextBox.focus();
However, if the page is displayed inside a modal dialog box, IE Only, then the Javascript errors.
Modal popups are an IE things, and do not work in firefox, and thus only IE has this problem.
WokaI have no idea what you mean by the page being displayed in "a modal dialog box".

I give focus using a javascript that is run on page load. It's always worked for me, and i only use IE.

Setting Initial Focus on a Text Box

How do i set the focus on a Textbox upon initial display of the page?<body onLoad="control.focus();"
>--Original Message--
>How do i set the focus on a Textbox upon initial display
of the page?

setting initial focus to textbox

I remember this from before but cant remember how to do it, its been over a
year since i have... how do you set the initial focus to a text box on page
load? isn't it a java script you have to do? thanksOn Sun, 4 Jul 2004 13:18:43 -0400, Brian Henry
<brianiupmsdn@.newsgroups.nospam> wrote:

> I remember this from before but cant remember how to do it, its been
> over a
> year since i have... how do you set the initial focus to a text box on
> page
> load? isn't it a java script you have to do? thanks
>
You are correct:
[url]http://www.dotnetjunkies.com/Tutorial/A7DC067E-A727-4FE5-904D-14BAAC5A5B7E.dcik[/u
rl]
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

setting initial focus to textbox

I remember this from before but cant remember how to do it, its been over a
year since i have... how do you set the initial focus to a text box on page
load? isn't it a java script you have to do? thanksOn Sun, 4 Jul 2004 13:18:43 -0400, Brian Henry
<brianiupmsdn@.newsgroups.nospam> wrote:

> I remember this from before but cant remember how to do it, its been
> over a
> year since i have... how do you set the initial focus to a text box on
> page
> load? isn't it a java script you have to do? thanks

You are correct:

http://www.dotnetjunkies.com/Tutori...BAAC5A5B7E.dcik

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Setting it up on my Win2K server

OK, I have just copied my project onto my live server and I can hit the website by typing in
http://ipaddress/websitename/default.aspx

However, I want it to allow all of my users to hit it from their client machines by typing in:
http://websitename

Can anyone tell me what I need to put on the server to resolve the name and how I do it?

I think it is something to do with DNS but im not sure.

AndyHi Andy

So your nameserver entry has to point to the ip address of your server. In the IIS configuration you have to set the webroot directory to for ex. "d:\data\websitename\". You also have to add the correct hostheader in the configuration so that your IIS knows what to show if someone wants to see www.yourwebsitename.com (This is only needed of you run more than one website on your server)

The hole thing shouldn't be to difficult.

Hope this helps.

Setting IsApproved to false on CreateUser Control

How can you set the IsApproved flag to false for all new registrations?
I am using the createUser wizard to setup my user registration page.

Thanks in advance,
JJI'm also running into dead ends trying figuring this one out.

Quoted from 4 Guys from rolla:
"
The Membership system enables user accounts to be marked as inactive
(not approved) and locked out. When creating a new user account, the
account is, by default, approved. However, in some scenarios you might
want to have an administrator manually approve new accounts before they
become active, or have the user progress through some automated process
(like clicking on a verification link sent through email). In either
case, the newly created user would be marked as inactive. Such a user
cannot log in to the site, as the ValidateUser(userName, password)
method will always return False, regardless of whether they entered
their correct credentials.
"

How can this default behavior be changed to "not approved" ?
Thanks much.
Mike

JJ wrote:

Quote:

Originally Posted by

How can you set the IsApproved flag to false for all new registrations?
I am using the createUser wizard to setup my user registration page.
>
Thanks in advance,
JJ

setting ItemTemplate value to DataList item index?

I have a datalist that outputs a link to a picture in each ItemTemplate:
e.g.
<asp:DataList id="DataList1" ...etc>
<ItemTemplate>
<a href='Pic.aspx?pic=somenumber'>picture</a>
</ItemTemplate>
<asp:DataList>
What I want to do is set the "pic=somenumber" querystring value
to the current DataList item's index.
e.g. something like:
Pic.aspx?pic=<%=DataList1.Items.Item.ItemIndex%>
This returns an error.
How can I retrieve the index of the current Item as it's loading the
template?
I could also create my own index value, that increments as the
DataList adds another ItemTemplate.. but not sure how to do this.
Thanks!
Peter
--
"I hear ma train a comin'
... hear freedom comin"Peter,
Two ways:
1. Use '<%# container.itemindex %>'
2. Create a public function on the page that bumps and returns a static
counter, e.g. (in vb)
Private m_Num As Integer = -1
Public Function NextNum() As Integer
m_Num += 1
Return m_Num
End Function
then...
'<%# NextNum() %>'
The first is easier, the second more extensible.
hth,
Bill
"Stimp" wrote:

> I have a datalist that outputs a link to a picture in each ItemTemplate:
> e.g.
> <asp:DataList id="DataList1" ...etc>
> <ItemTemplate>
> <a href='Pic.aspx?pic=somenumber'>picture</a>
> </ItemTemplate>
> <asp:DataList>
> What I want to do is set the "pic=somenumber" querystring value
> to the current DataList item's index.
> e.g. something like:
> Pic.aspx?pic=<%=DataList1.Items.Item.ItemIndex%>
> This returns an error.
> How can I retrieve the index of the current Item as it's loading the
> template?
> I could also create my own index value, that increments as the
> DataList adds another ItemTemplate.. but not sure how to do this.
> Thanks!
> Peter
> --
> "I hear ma train a comin'
> ... hear freedom comin"
>
P.S. Per Weston's comment, I too prefer to do most things of any complexity
in the code-behind. What he suggested will work great.
"Bill Borg" wrote:
> Peter,
> Two ways:
> 1. Use '<%# container.itemindex %>'
> 2. Create a public function on the page that bumps and returns a static
> counter, e.g. (in vb)
> Private m_Num As Integer = -1
> Public Function NextNum() As Integer
> m_Num += 1
> Return m_Num
> End Function
> then...
> '<%# NextNum() %>'
> The first is easier, the second more extensible.
> hth,
> Bill
> "Stimp" wrote:
>
On Fri, 10 Sep 2004 Bill Borg <BillBorg@.discussions.microsoft.com> wrote:
> Peter,
> Two ways:
> 1. Use '<%# container.itemindex %>'
That's EXACTLY what I was looking for!
Thanks to all who replied!
--
"I hear ma train a comin'
... hear freedom comin"

setting ItemTemplate value to DataList item index?

I have a datalist that outputs a link to a picture in each ItemTemplate:

e.g.
<asp:DataList id="DataList1" ...etc>
<ItemTemplate>
<a href='Pic.aspx?pic=somenumber'>picture</a>
</ItemTemplate>
<asp:DataList
What I want to do is set the "pic=somenumber" querystring value
to the current DataList item's index.

e.g. something like:

Pic.aspx?pic=<%=DataList1.Items.Item.ItemIndex%
This returns an error.

How can I retrieve the index of the current Item as it's loading the
template?
I could also create my own index value, that increments as the
DataList adds another ItemTemplate.. but not sure how to do this.

Thanks!
Peter
--

"I hear ma train a comin'
... hear freedom comin"I dont have a development machine in front of me at the
moment, but I do know that a lot of other .net
databindable lists have OnItemDataBound, and OnItemCreated
events.

If it has a OnItemDataBound event, it'd be REAL easy.
throw some winforms control in the template, then you can
modify it from the code behind

if(e.ItemType == ListItemType.ListItem){
((LinkButton) e.FindControl("myLinkButton")).LinkUrl =
e.Item.ItemIndex;

}

Something along those lines. I know it works for DataGrid
and I am pretty sure data list too, but I dont think it
works with repeater.

>--Original Message--
>I have a datalist that outputs a link to a picture in
each ItemTemplate:
>e.g.
><asp:DataList id="DataList1" ...etc>
> <ItemTemplate>
> <a href='Pic.aspx?pic=somenumber'>picture</a>
> </ItemTemplate>
><asp:DataList>
>What I want to do is set the "pic=somenumber" querystring
value
>to the current DataList item's index.
>e.g. something like:
>Pic.aspx?pic=<%=DataList1.Items.Item.ItemIndex%>
>This returns an error.
>How can I retrieve the index of the current Item as it's
loading the
>template?
>I could also create my own index value, that increments
as the
>DataList adds another ItemTemplate.. but not sure how to
do this.
>Thanks!
>Peter
>--
>"I hear ma train a comin'
>... hear freedom comin"
>.
P.S. Per Weston's comment, I too prefer to do most things of any complexity
in the code-behind. What he suggested will work great.

"Bill Borg" wrote:

> Peter,
> Two ways:
> 1. Use '<%# container.itemindex %>'
> 2. Create a public function on the page that bumps and returns a static
> counter, e.g. (in vb)
> Private m_Num As Integer = -1
> Public Function NextNum() As Integer
> m_Num += 1
> Return m_Num
> End Function
> then...
> '<%# NextNum() %>'
> The first is easier, the second more extensible.
> hth,
> Bill
> "Stimp" wrote:
> > I have a datalist that outputs a link to a picture in each ItemTemplate:
> > e.g.
> > <asp:DataList id="DataList1" ...etc>
> > <ItemTemplate>
> > <a href='Pic.aspx?pic=somenumber'>picture</a>
> > </ItemTemplate>
> > <asp:DataList>
> > What I want to do is set the "pic=somenumber" querystring value
> > to the current DataList item's index.
> > e.g. something like:
> > Pic.aspx?pic=<%=DataList1.Items.Item.ItemIndex%>
> > This returns an error.
> > How can I retrieve the index of the current Item as it's loading the
> > template?
> > I could also create my own index value, that increments as the
> > DataList adds another ItemTemplate.. but not sure how to do this.
> > Thanks!
> > Peter
> > --
> > "I hear ma train a comin'
> > ... hear freedom comin"
On Fri, 10 Sep 2004 Bill Borg <BillBorg@.discussions.microsoft.com> wrote:
> Peter,
> Two ways:
> 1. Use '<%# container.itemindex %>'

That's EXACTLY what I was looking for!

Thanks to all who replied!
--

"I hear ma train a comin'
... hear freedom comin"

Setting ItemStyle CssClass programmatically

I would like to have something like this;
<asp:TemplateColumn ...>
<ItemStyle CssClass='<%# DataBinder.Eval(Container,"DataItem.Style")%>'>
</ItemStyle>
<ItemTemplate>
..
</ItemTemplate>
</asp:TemplateColumn>
Where I get the style for the TemplateColumn from the datasource (or compute
it based on the datasource)
It doesn't appear that I can set the CssClass attribute in this manner.
I'm not sure why it should be different from, for example, the Text attribut
e
of an asp:Label.
Thanks,
BradBrad,
It's a matter of how they are implemented, the *Style are simply properties
of the Grid, whereas the *Templates are actulaly templates - which is what
allows you to have binding information on then. In other words, the
ItemStyle applies to all rows of the grid, not just the current one being
binded.
If this is important, one thing you might look at is using a Repeater.
You'll have more control over what's being rendered, for instance, since the
TR isn't automatically generated, you need to put it in your ItemTemplate,
which should allow what you need to do:
<asp:repeater ...>
<headerTemplate>
<table>
</headerTemplate>
<itemTemplate>
<tr class='<%# DataBinder.Eval(Container,"DataItem.Style")%>'>
<td>blah</td>
</tr>
</itemTemplate>
<footerTemplate>
</table>
</footerTemplate>
</asp:repeater>
"Brad Quinn" <BradQuinn@.discussions.microsoft.com> wrote in message
news:358028B3-2484-4063-93F6-D2C3664F861F@.microsoft.com...
> I would like to have something like this;
> <asp:TemplateColumn ...>
> <ItemStyle CssClass='<%# DataBinder.Eval(Container,"DataItem.Style")%>'>
> </ItemStyle>
> <ItemTemplate>
> ...
> </ItemTemplate>
> </asp:TemplateColumn>
> Where I get the style for the TemplateColumn from the datasource (or
compute
> it based on the datasource)
> It doesn't appear that I can set the CssClass attribute in this manner.
> I'm not sure why it should be different from, for example, the Text
attribute
> of an asp:Label.
> Thanks,
> Brad

Setting label = datasource...

Could someone please post some sample code on how to set an <asp:label>
equal to the results of a sql query?
This seems like it should be simple, but I can't seem to get it done.Well what do you get as a return? a SqlDataReader, DataView?
to get every row into the table you'll have to loop around, otherwise, use a
DataGrid to display row by row:
while(pData.Read())
Label.Text += pData.GetString(0);
Hope you getting string!
Al
"Roy" wrote:

> Could someone please post some sample code on how to set an <asp:label>
> equal to the results of a sql query?
> This seems like it should be simple, but I can't seem to get it done.
>
y,
If you are going to have only one value in your result of a sqlquery thenyou
can use the following code to bind that single value to a label box.
Store that single value in a variable,say "MyVariable" for example, and
assign it to label cotrol as follows.
<asp:Label id="Label1" Text ='<%# MyVariable %>' runat=server/>
You've to write the following line in one of your event's let us Page_Load
event
Page.DataBind();
cheers,
Jerome. M
"Roy" wrote:

> Could someone please post some sample code on how to set an <asp:label>
> equal to the results of a sql query?
> This seems like it should be simple, but I can't seem to get it done.
>
Thanks for the input guys.
Basically, I'm trying to set a label equal to a specific row in a
table. The row would have about 6 columns in it, but it would always be
just a single row. By the same token, I'd like it to look good... Can I
set it equal to a specific field? IOW, break up the row into it's
constituent parts?

Setting label = datasource...

Could someone please post some sample code on how to set an <asp:label>
equal to the results of a sql query?

This seems like it should be simple, but I can't seem to get it done.Well what do you get as a return? a SqlDataReader, DataView?
to get every row into the table you'll have to loop around, otherwise, use a
DataGrid to display row by row:

while(pData.Read())
Label.Text += pData.GetString(0);

Hope you getting string!

Al

"Roy" wrote:

> Could someone please post some sample code on how to set an <asp:label>
> equal to the results of a sql query?
> This seems like it should be simple, but I can't seem to get it done.
>
y,

If you are going to have only one value in your result of a sqlquery thenyou
can use the following code to bind that single value to a label box.

Store that single value in a variable,say "MyVariable" for example, and
assign it to label cotrol as follows.

<asp:Label id="Label1" Text ='<%# MyVariable %>' runat=server/
You've to write the following line in one of your event's let us Page_Load
event

Page.DataBind();

cheers,

Jerome. M
"Roy" wrote:

> Could someone please post some sample code on how to set an <asp:label>
> equal to the results of a sql query?
> This seems like it should be simple, but I can't seem to get it done.
>
Thanks for the input guys.

Basically, I'm trying to set a label equal to a specific row in a
table. The row would have about 6 columns in it, but it would always be
just a single row. By the same token, I'd like it to look good... Can I
set it equal to a specific field? IOW, break up the row into it's
constituent parts?

Setting label text from database from code behind

I have this function in my code behind file...


Function GetPageTitle() As System.Data.DataSet
Dim connectionString As String = "server=xxx; user id=xxx; password=xx; database=xx"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim CurrentPageName As String = Request.Params("pagename")
'create the connection object
'Dim connection As New SqlConnection(connectionString)

Dim queryString As String = "SELECT [Content].[PageTitle] FROM [Content] WHERE ([Content].[Page" & _
"Name] = @dotnet.itags.org.CurrentPageName)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_pagename As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_pagename.ParameterName = "@dotnet.itags.org.CurrentPageName"
dbParam_pagename.Value = CurrentPageName
dbParam_pagename.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_pagename)

Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function

and I would like it to return a text value to set the text of this label


<asp:label id="PageTitleLabel" runat="server" Text="<%# GetPageTitle () %>"></asp:label>

I also call page.databind in page load.

The result I get when I run the page is "System.Data.DataSet" as the label text!!!

I can find plenty of books and articles databinding grids, lists and repeaters but all I want is a humble label.

Thanks

SimonOK, you are assigning a whole dataset to a text field, so it will simply get the Object name which is "System.Data.DataSet" Try this, instead of having the function return a dataset "As System.Data.DataSet" return a string "As String". Now when you populate the DataSet inside your function (I don't know how many records you will get on the DataSet) find the record in the DataSet and return is as a string like:

This is C#


Return dataSet["page_title"].ToString();

Now you have the page title returned instead of the entire dataset.

Good Luck
Thanks for the response.

I got me on the right road.

Simon

Setting label text = textbox text on other form

How can I set the text of a label on a user control equal to whatever the user types into a textbox on a .aspx file?

Is there any easy way of referencing the label in the .ascx file?Create a property in the user control

public property Text {
get { return label1.text }
set { label1.text = value; }
}

the property changes the value.

Brian
Hi !!

Is that code will make the label text as same as the textbox text on runtime like filling a textbox with some text amd click on button (as example) then i see the text of the label is what i typed in the box. Is that really the benefit of this code. If there is a different idea or i got that wrong please advise!! Thanks
Thanks for that.

Can you tell me if that should be in the .ascx file or the .ascx.vb file?

Will this work for setting the user control label text = text box on another form?
I think this is what you are looking for. If you are using code-behind, always put code in the code-behind (the .vb or .cs file); otherwise, you have no choice to put it in the .ascx file.

Brian
The property exposes a field in the user control without providing direct control, so if you want to encode the text or do something else to it (like trim it), you can.

Brian
This is what I have done so far

In the .ascx.vb class I have added the folowing class:


Public Class Logon
Inherits System.Web.UI.UserControl

Private username As String

Public Property Name() As String
Get
Return username
End Get
Set(ByVal Value As String)
username = Value
End Set
End Property

End Class

and within .aspx.vb file I have added this:

<ACME:GETEST id="GETEST1" runat="server" username="xyz" OnNavigate="TestControl_OnNavigate"></ACME:GETEST

And this is where the label I want to set the text on is declared in the codebehind file of the usercontrol.


Public MustInherit Class WebUserControl1

Protected WithEvents lblUser As System.Web.UI.WebControls.Label

Now how do I actually set the text of the label - how do I call the class?
I'm a little confused of the layout. If Logon is your user control code-behind page, and you have the lblUser label within that user control (in the .ascx), then put the Protected WithEvents statement for the lblUser in the Logon code-behind, and do:

Public Property Name() As String

Get

Return lblUser.Text

End Get

Set(ByVal Value As String)

lblUser.Text = Value

End Set

End Property

Brian
Heres the file named GENav.ascx.vb:


Public MustInherit Class WebUserControl1
Inherits System.Web.UI.UserControl

Protected WithEvents lblUser As System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

End Sub

'Other code ...

Public Class Logon
Inherits System.Web.UI.UserControl
Protected WithEvents lblUser As System.Web.UI.WebControls.Label

Private username As String

Public Property Name() As String
Get
Return username
End Get
Set(ByVal Value As String)
username = Value

End Set
End Property

End Class

And the textbox is in an .aspx file.

When the user clicks a button to Logon, I want their Logon name entered in the textbox to appear on the label lblUser in the User Control.

Im just not sure how to call the Public Property Name() As String part and to use what the user entered in the textbox.
What do you use this for: WebUserControl1? You don't have anything inheriting from it (as you declared it MustInherit). Also, a user control class that inherits from this cannot define controls in the base, and inherit them in that way. You need to define all of the controls in the Logon user control, and each control must have a Protected WithEvents declaration in the code-behind.

Whenever the login button is clicked, then you make that assignment. Is the lblUser label in the same user control as login, or are we talking about a different user control (the first one)? I'm confused..

Brian
There is only one user control this is where the lblUser label is.

WebUserControl1 was code I didnt write - added by the system and I dont really know what its for but it was working fine so I just went with it.

The button I want to do the assignment of the textbox text to the label is just in a .aspx file so its on a web form.

I added the code in the Logon class below trying to do what you said earlier so the Logon class didnt exist before this.


Public Class Logon
Inherits System.Web.UI.UserControl
Protected WithEvents lblUser As System.Web.UI.WebControls.Label

Private username As String

Public Property Name() As String
Get
Return username
End Get
Set(ByVal Value As String)
username = Value

End Set
End Property

End Class


SO if the button is in the user control, you need a Protected WithEvents definition for that too; that should be generated by VS.NET if you are using that; are you? If you have that to, for the link button's click event, then if the user logs in, assign the user name text in the textbox (also needing a protected withevents statement) to the label. You wouldn't need the property if you didn't want to, or could use it as readonly to state what the username was. I wouldn't assign the value to a string, but would assign it directly to the label.

Brian
Also in continuing, it may help to post the entire .ascx.cs file for login control and the entire HTML code .ascx. Leave out the other code that you aren't using; that's generated by the .NET editor.

Brian
The button is not in the user control it is in the web form.
Yes I am using VS.NET.

Here is all the code as it was before I started trying to assign the textbox to label text:
GENav.ascx.vb file:


Public MustInherit Class WebUserControl1
Inherits System.Web.UI.UserControl
Protected WithEvents btnHome As System.Web.UI.WebControls.Button
Protected WithEvents btnSearch As System.Web.UI.WebControls.Button
Protected WithEvents btnUpdate As System.Web.UI.WebControls.Button
Protected WithEvents btnView As System.Web.UI.WebControls.Button
Protected WithEvents btnLogout As System.Web.UI.WebControls.Button
Protected WithEvents btnGuide As System.Web.UI.WebControls.Button
Protected WithEvents lblUser As System.Web.UI.WebControls.Label
Protected WithEvents lblTime As System.Web.UI.WebControls.Label
Protected WithEvents PnlHeader As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents PnlNav As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
Protected WithEvents lblHeader As System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

'Display date and time
Dim dtNow As DateTime = DateTime.Now
lblTime.Text = dtNow.ToString

End Sub

Sub Login_OnNavigate(ByVal sender As Object, ByVal e As EventArgs)

'lblUser.Text = ((CType(sender, Control).ID))

End Sub

Private Sub lkAdmin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub

Private Sub btnHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHome.Click

End Sub

Private Sub btnLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogout.Click

End Sub

Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click

End Sub
End Class

The GENav.ascx file:


<%@. Control Language="vb" AutoEventWireup="false" Codebehind="GENav.ascx.vb" Inherits="WebApplication1.WebUserControl1" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<script type="text/javascript"
window.moveTo(0,0);

if (document.all) {

top.window.resizeTo(

screen.availWidth,

screen.availHeight);

} else if (document.layers

|| document.getElementById) {

if (top.window.outerHeight < screen.availHeight ||
top.window.outerWidth < screen.availWidth){

top.window.outerHeight = screen.availHeight;

top.window.outerWidth = screen.availWidth;

}

}
</script>
<script runat="server"
Event Navigate As EventHandler

Sub btnHome_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnHome.Click
OnNavigate(sender, e)
End Sub

Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
OnNavigate(sender, e)
End Sub

Sub btnView_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnView.Click
OnNavigate(sender, e)
End Sub

Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
OnNavigate(sender, e)
End Sub

Sub btnGuide_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGuide.Click
OnNavigate(sender, e)
End Sub

Sub btnLogout_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogout.Click
OnNavigate(sender, e)

btnLogout.Text = "Logout"

End Sub

Overridable Sub OnNavigate(ByVal sender As Object, ByVal e As EventArgs)
RaiseEvent Navigate(sender, e)
End Sub

</script>
<DIV id="PnlHeader" style="LEFT: 15%; WIDTH: 88%; POSITION: absolute; TOP: 0%; HEIGHT: 20%; BACKGROUND-COLOR: #2b4d96" onclick="BtnHome_Click" runat="server" ms_positioning="GridLayout"><asp:label id="lblHeader" style="LEFT: 5%; POSITION: absolute; TOP: 40%" runat="server" BackColor="#2B4D96" Width="95%" ForeColor="White" Font-Bold="True" Height="40%" Font-Size="Large" Font-Names="Rockwell Extra Bold">Header</asp:label></DIV>
<DIV id="PnlNav" style="LEFT: -14px; WIDTH: 20.69%; POSITION: absolute; TOP: -14px; HEIGHT: 100%; BACKGROUND-COLOR: #2b4d96" runat="server" ms_positioning="GridLayout"><asp:button id="btnHome" style="Z-INDEX: 102; LEFT: 22px; POSITION: absolute; TOP: 111px" runat="server" BackColor="White" Width="80%" ForeColor="#2B4D96" Font-Bold="True" Runat="server" Text="Home"></asp:button><asp:button id="btnSearch" style="Z-INDEX: 103; LEFT: 20px; POSITION: absolute; TOP: 145px" runat="server" BackColor="White" Width="80%" ForeColor="#2B4D96" Font-Bold="True" Text="Search"></asp:button><asp:button id="btnUpdate" style="Z-INDEX: 104; LEFT: 21px; POSITION: absolute; TOP: 211px" runat="server" BackColor="White" Width="80%" ForeColor="#2B4D96" Font-Bold="True" Text=" Update Orders"></asp:button><asp:button id="btnView" style="Z-INDEX: 105; LEFT: 22px; POSITION: absolute; TOP: 180px" runat="server" BackColor="White" Width="80%" ForeColor="#2B4D96" Font-Bold="True" Text="View Orders"></asp:button><asp:button id="btnLogout" style="Z-INDEX: 106; LEFT: 21px; POSITION: absolute; TOP: 279px" runat="server" BackColor="White" Width="80%" ForeColor="#2B4D96" Font-Bold="True" Text="Log In"></asp:button><asp:button id="btnGuide" style="Z-INDEX: 107; LEFT: 20px; POSITION: absolute; TOP: 242px" runat="server" BackColor="White" Width="80%" ForeColor="#2B4D96" Font-Bold="True" Text="Online Guide"></asp:button><asp:label id="lblUser" style="Z-INDEX: 108; LEFT: 29px; POSITION: absolute; TOP: 332px" runat="server" Width="80%" ForeColor="White" Font-Bold="True" Height="24px"></asp:label><asp:label id="lblTime" style="Z-INDEX: 109; LEFT: 29px; POSITION: absolute; TOP: 368px" runat="server" Width="80%" ForeColor="White" Font-Bold="True" Height="36px"></asp:label><asp:hyperlink id="HyperLink1" style="Z-INDEX: 110; LEFT: 21px; POSITION: absolute; TOP: 310px" runat="server" ForeColor="White" NavigateUrl="Admin.aspx">Administrator</asp:hyperlink></DIV>

This is the web form:


<%@. Page Language="vb" AutoEventWireup="false" Codebehind="GELogin.aspx.vb" Inherits="WebApplication1.WebForm2"%>
<%@. Register TagPrefix="ACME" TagName="GETEST" src="http://pics.10026.com/?src=GENav.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>GELogin</title>
<script runat="server"
Sub TestControl_OnNavigate(ByVal sender As Object, ByVal e As EventArgs)
Response.Write((CType(sender, Control).ID + " was clicked"))
lblNavClick.Text = ((CType(sender, Control).ID))

if lblNavClick.Text = "btnLogout" Then

PnlPassword.Visible = True

txtUsername.Text = ""
txtPassword.Text = ""
End If

End If

End Sub 'TestControl_OnNavigate
</script>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<BODY>
<form id="Form1" method="post" runat="server">
<ACME:GETEST id="GETEST1" runat="server" OnNavigate="TestControl_OnNavigate"></ACME:GETEST
<DIV id="PnlPassword" style="Z-INDEX: 106; LEFT: 20%; WIDTH: 60%; BORDER-TOP-STYLE: groove; BORDER-RIGHT-STYLE: groove; BORDER-LEFT-STYLE: groove; POSITION: absolute; TOP: 22%; HEIGHT: 70%; BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM-STYLE: groove" runat="server" ms_positioning="GridLayout">
<DIV id="lblUsername" style="DISPLAY: inline; LEFT: 5%; WIDTH: 30%; POSITION: absolute; TOP: 30%; HEIGHT: 10%" ms_positioning="FlowLayout">User
Name:
</DIV>
<DIV id="lblPassword" style="DISPLAY: inline; LEFT: 5%; WIDTH: 20%; POSITION: absolute; TOP: 50%; HEIGHT: 10%" ms_positioning="FlowLayout">Password:</DIV>

<asp:button id="btnGo" style="LEFT: 50%; POSITION: absolute; TOP: 80%" runat="server" Height="10%" Width="20%" Text="Go >"></asp:button><asp:textbox id="txtUsername" style="LEFT: 30%; POSITION: absolute; TOP: 30%" runat="server" Height="10%" Width="40%"></asp:textbox><asp:textbox id="txtPassword" style="LEFT: 30%; POSITION: absolute; TOP: 50%" runat="server" Height="10%" Width="40%" TextMode="Password"></asp:textbox><asp:label id="lblDirections" style="LEFT: 10%; POSITION: absolute; TOP: 5%" runat="server" Height="10%" Width="90%" Font-Size="Medium" BackColor="White" Font-Bold="True" ForeColor="Navy">Enter your User Name and Password
below:</asp:label><asp:linkbutton id="lkNewAccount" style="LEFT: 75%; POSITION: absolute; TOP: 20%" runat="server" Height="10%" Width="20%" Font-Size="X-Small">New User</asp:linkbutton><asp:button id="btnClear" style="LEFT: 25%; POSITION: absolute; TOP: 80%" runat="server" Height="10%" Width="20%" Text="Clear"></asp:button>
<P><asp:linkbutton id="lkChangePwd" style="LEFT: 75%; POSITION: absolute; TOP: 40%" runat="server" Height="10%" Width="20%" Font-Size="X-Small">Change Password</asp:linkbutton><asp:linkbutton id="lkForgotten" style="LEFT: 75%; POSITION: absolute; TOP: 60%" runat="server" Height="10%" Width="20%" Font-Size="X-Small">Forgotten your
Password?</asp:linkbutton></P>
</DIV>
</form>
</BODY>
</HTML>

And this is the GELogin.aspx.vb file (codebehind for Web Form)


Imports System.Data
Imports System.Data.SqlClient

Public Class WebForm2
Inherits System.Web.UI.Page

Protected WithEvents txtnewPwd2 As System.Web.UI.WebControls.TextBox
Protected WithEvents lblnewPwd2 As System.Web.UI.WebControls.Label
Protected WithEvents txtnewPwd1 As System.Web.UI.WebControls.TextBox
Protected WithEvents lblnewPwd1 As System.Web.UI.WebControls.Label
Protected WithEvents txtUserpwdchange As System.Web.UI.WebControls.TextBox
Protected WithEvents lblPwdChangeuser As System.Web.UI.WebControls.Label
Protected WithEvents txtoldpwd As System.Web.UI.WebControls.TextBox
Protected WithEvents lbloldpwd As System.Web.UI.WebControls.Label
Protected WithEvents lblGivenemail As System.Web.UI.WebControls.Label
Protected WithEvents btnchangePwdBack As System.Web.UI.WebControls.Button
Protected WithEvents lblChangepwd As System.Web.UI.WebControls.Label
Protected WithEvents btnGoChangePwd As System.Web.UI.WebControls.Button

Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents txtemail As System.Web.UI.WebControls.TextBox
Protected WithEvents lblemail As System.Web.UI.WebControls.Label
Protected WithEvents btnGo As System.Web.UI.WebControls.Button
Protected WithEvents txtUsername As System.Web.UI.WebControls.TextBox
Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
Protected WithEvents lblDirections As System.Web.UI.WebControls.Label
Protected WithEvents lkNewAccount As System.Web.UI.WebControls.LinkButton
Protected WithEvents lblResponse As System.Web.UI.WebControls.Label
Protected WithEvents btnClear As System.Web.UI.WebControls.Button
Protected WithEvents lkChangePwd As System.Web.UI.WebControls.LinkButton
Protected WithEvents lkForgotten As System.Web.UI.WebControls.LinkButton
Protected WithEvents PnlPassword As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents lblWelcome As System.Web.UI.WebControls.Label
Protected WithEvents lblNavClick As System.Web.UI.WebControls.Label
Protected WithEvents lkLogon As System.Web.UI.WebControls.LinkButton
Protected WithEvents lblUserLoggedIn As System.Web.UI.WebControls.Label
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

End Sub

Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click

If txtUsername.Text = "" Or txtPassword.Text = "" Then

PnlPassword.Visible = True
'Its here I want the text from txtUserName.Text to be assigned to the label in the user control
'Generates the message:
Dim strMessage As String

strMessage = "Enter a User Name & Password to proceed"

'finishes server processing, returns to client.
Dim strScript As String = "<script language=JavaScript>"
strScript += "alert(""" & strMessage & """);"
strScript += "</script>"

If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If

Else
PnlScreen.Visible = True
PnlPassword.Visible = False

End If
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtUsername.Text = ""
txtPassword.Text = ""
PnlPassword.Visible = True
PnlScreen.Visible = False

End Sub

End Class


Can you see what I am trying to achieve a bit clearer now?
i will assume the following, correct me if i'm wrong.

1) you have an aspx page with a textbox and a button and a usercontrol containing a label
2) the user enters a name, and clicks submit, the page then does a postback
3) the usercontrol label changes to the textbox text.

to do this...

1) add this to the aspx page

Protected WithEvents m_UserControl As WebUserControl1 (your control type)

2) in design view of the aspx page, click the button and add the following code.. change the findcontrol string to the name of the control in the TagName attribute at the top of the aspx page.

m_UserControl= CType(FindControl("Webusercontrol11"), WebUserControl1)
m_UserControl.TextValue = txtname.Text

this should do what you need.

i think it has all been said in the post earlier, but it looks like things got confusing.

Setting language AJAX controls

I would like to customize the ASP.NET AJAX Controls in spanish...

How can this be done, specifically for the CalendarExtender?

Hey,

The calendar extender is part of the AJAXControlToolkit; doesn't it already support spanish? I know it supported several languages (as it creates a bunch of language folders when you import it). If it doesn't support spanish already, I would be shocked by that.


The Ajax toolkit loads a bunch of resource files for many languages but how do I set that property... I have my whole website set to

<globalizationculture="es-ES"uiCulture="es-ES"/>

Obviously in the webconfig but those values seem not to be affecting the calendar's layout at all.


Hi algarrobo,

If you mean this control:

http://asp.net/AJAX/Control-Toolkit/Live/Calendar/Calendar.aspx

It is already localized as brian said. First please make sure you are using the latest ASP.NET AJAX Control Toolkit.

Based on my understanding, you also need to set theEnableScriptGlobalization andEnableScriptLocalization properties of ScriptManager to true.

When theEnableScriptGlobalization property is set totrue, globalized ECMAScript (JavaScript) functions such as theDate.localeFormat method display culture-specific information.

http://www.asp.net/ajax/documentation/live/mref/P_System_Web_UI_ScriptManager_EnableScriptGlobalization.aspx

While theEnableScriptLocalization property is used by ScriptManager object to retrieve script files for the current culture.

http://www.asp.net/AJAX/Documentation/Live/mref/P_System_Web_UI_ScriptManager_EnableScriptLocalization.aspx

Setting labels font-bold attribute to True from sub or function?

This should be really easy. How in the world can I set a label's font-bold attribute to TRUE in a sub routine?

lblMyLabel.Font-Bold= True
lblMyLabel.Text = "HELLO!"
lblMyLabel.ForeColor = Drawing.Color.RedJust like you are doing right now?
Label1.Font.Bold = true;

What's acutally going wrong with your code?

Setting link dynamically

On Tue, 2 Jan 2007 14:49:00 -0500, "Karl Seguin"
<karlremove@dotnet.itags.org.removeopenmymindremovemetoo.andmenet> wrote:
As where a bigger project would be better approached how?
I'm fairly new to aspnet (and websites in general), so please be as
specific as possible as I'm sucking up all knowledge I stumble upon.

>Your data access layer and presentation layers are glued..which is fine for
>a small project.At the very least, it's generally a good idea to have your dataaccess layer
sit in it's own class which your codebehind files can leverage.
something like:
Button_Click()
dim dal as new DataAccess()
dal.AddUser(User.Text, Password.Text)
end sub
or something..
For larger projects, you typically want a full domain layer...so you do
something like:
dim user as User = User.CreateNewUser();
user.FirstName = FirstName.Text;
user.LastName = LastName.Text;
user.Save();
I left out the validation you'd normally have..
Karl
http://www.openmymind.net/
http://www.fuelindustries.com/
"Morten Snedker" <fido@.alotofsites.com> wrote in message
news:nfllp25mq6r3d354qev9tr5c06p868gd12@.
4ax.com...
> On Tue, 2 Jan 2007 14:49:00 -0500, "Karl Seguin"
> <karlremove@.removeopenmymindremovemetoo.andmenet> wrote:
> As where a bigger project would be better approached how?
> I'm fairly new to aspnet (and websites in general), so please be as
> specific as possible as I'm sucking up all knowledge I stumble upon.
>
>

Setting link dynamically

Sam's comments were very good also.
As for casting..
dim control as Control = FindControl(reader(1).ToString())
if (control is nothing) then
'throw an exception maybe? depends whether this is exceptional or not
else if (control is HtmlImage)
dim h as HtmlImage = ctype(control, HtmlImage)
h.NavigateUrl = ...
else if (control is TextBox)
dim t as TextBox = ctype(control, TextBox)
t.Text = reader(1).ToString()
end if
Karl
http://www.openmymind.net/
http://www.fuelindustries.com/
"Morten Snedker" <fido@dotnet.itags.org.alotofsites.com> wrote in message
news:veklp2l99u9u4pvm635cs0fq7f67eb3o65@dotnet.itags.org.
4ax.com...
> Auch, you're evil! :-)
> I suppose you by rough refer to something like
> h = FindControl(reader(1).ToString)
> , which I guess you knew would produce an error due to the implicit
> type conversion, when having Option Strict set. Though, I just can't
> figure out how to do the casting that makes i work..? And I really
> tried! :-)
>
> Regards /Snedker
>
> On Tue, 2 Jan 2007 14:49:00 -0500, "Karl Seguin"
> <karlremove@dotnet.itags.org.removeopenmymindremovemetoo.andmenet> wrote:
>
>On Wed, 3 Jan 2007 08:25:39 -0500, "Karl Seguin"
<karlremove@.removeopenmymindremovemetoo.andmenet> wrote:
It was the CType thing I'd forgotten all about. Funny how it slips
when you've been away from it for only a short while.
Thanks to both you and Sam for your fine resonse.
Regards /Morten

Setting listbox items

I have a string that I read from my database: 1|8|5620|541

These are all values in my ListBox. I want to select each of these items (4
of them - but could be many more). At the moment I am doing the following:

Dim a() As String
Dim j As Integer
a = JobCategoriesSelected.Split("|") ' Where
JobCategoriesSelected is set to 1|8|5620|541
For j = 0 To a.GetUpperBound(0)
trace.warn("string = " & a(j))
for each item as ListItem in JobCategories.items
if item.value = a(j) then
item.selected = true
end if
next
Next

The problem is that for each Item I am selecting, I am having to go through
the list to find the value that matches the one I want to set. In this
case, it would have to go through the list 4 times.

Is there some kind of a way to do it in one line where you say something
like set the listitem that is equal to my value to selected?

Thanks,

Tom
dim item as ListItem = jobCategories.ITems.FindbyValue(a(j))
if not item is nothing then
item.selected = true
end if

Btw, why bother using a relationa database (assuming) if you are gonna use
values which are split like that?

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!)
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:OXpbQjTOFHA.3144@.tk2msftngp13.phx.gbl...
> I have a string that I read from my database: 1|8|5620|541
> These are all values in my ListBox. I want to select each of these items
(4
> of them - but could be many more). At the moment I am doing the
following:
> Dim a() As String
> Dim j As Integer
> a = JobCategoriesSelected.Split("|") ' Where
> JobCategoriesSelected is set to 1|8|5620|541
> For j = 0 To a.GetUpperBound(0)
> trace.warn("string = " & a(j))
> for each item as ListItem in JobCategories.items
> if item.value = a(j) then
> item.selected = true
> end if
> next
> Next
> The problem is that for each Item I am selecting, I am having to go
through
> the list to find the value that matches the one I want to set. In this
> case, it would have to go through the list 4 times.
> Is there some kind of a way to do it in one line where you say something
> like set the listitem that is equal to my value to selected?
> Thanks,
> Tom
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e86j1GUOFHA.1476@.TK2MSFTNGP09.phx.gbl...
>
> dim item as ListItem = jobCategories.ITems.FindbyValue(a(j))
> if not item is nothing then
> item.selected = true
> end if

I knew there was a better way.

> Btw, why bother using a relationa database (assuming) if you are gonna use
> values which are split like that?

What I am doing is storing the string in a field that shows which choices
the user made to a ListBox (could have many). I am collecting the values
and separating them by "|". The Job Categories are themselves in a table
("text and value"). But each user can have many search records (each of
which can have a different set of Job Categories). This seemed like the
best way to save it.

Thanks,

Tom
> 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!)
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:OXpbQjTOFHA.3144@.tk2msftngp13.phx.gbl...
>> I have a string that I read from my database: 1|8|5620|541
>>
>> These are all values in my ListBox. I want to select each of these items
> (4
>> of them - but could be many more). At the moment I am doing the
> following:
>>
>> Dim a() As String
>> Dim j As Integer
>> a = JobCategoriesSelected.Split("|") ' Where
>> JobCategoriesSelected is set to 1|8|5620|541
>> For j = 0 To a.GetUpperBound(0)
>> trace.warn("string = " & a(j))
>> for each item as ListItem in JobCategories.items
>> if item.value = a(j) then
>> item.selected = true
>> end if
>> next
>> Next
>>
>> The problem is that for each Item I am selecting, I am having to go
> through
>> the list to find the value that matches the one I want to set. In this
>> case, it would have to go through the list 4 times.
>>
>> Is there some kind of a way to do it in one line where you say something
>> like set the listitem that is equal to my value to selected?
>>
>> Thanks,
>>
>> Tom
>>
>>
Seems like a join table is the best way

UserId, JobId

1,1
1,3
1,5
2,4
5,1
5,6

...

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!)
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:OsMYwLUOFHA.2384@.tk2msftngp13.phx.gbl...
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:e86j1GUOFHA.1476@.TK2MSFTNGP09.phx.gbl...
> > dim item as ListItem = jobCategories.ITems.FindbyValue(a(j))
> > if not item is nothing then
> > item.selected = true
> > end if
> I knew there was a better way.
> > Btw, why bother using a relationa database (assuming) if you are gonna
use
> > values which are split like that?
> What I am doing is storing the string in a field that shows which choices
> the user made to a ListBox (could have many). I am collecting the values
> and separating them by "|". The Job Categories are themselves in a table
> ("text and value"). But each user can have many search records (each of
> which can have a different set of Job Categories). This seemed like the
> best way to save it.
> Thanks,
> Tom
> > 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!)
> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> > news:OXpbQjTOFHA.3144@.tk2msftngp13.phx.gbl...
> >> I have a string that I read from my database: 1|8|5620|541
> >>
> >> These are all values in my ListBox. I want to select each of these
items
> > (4
> >> of them - but could be many more). At the moment I am doing the
> > following:
> >>
> >> Dim a() As String
> >> Dim j As Integer
> >> a = JobCategoriesSelected.Split("|") ' Where
> >> JobCategoriesSelected is set to 1|8|5620|541
> >> For j = 0 To a.GetUpperBound(0)
> >> trace.warn("string = " & a(j))
> >> for each item as ListItem in JobCategories.items
> >> if item.value = a(j) then
> >> item.selected = true
> >> end if
> >> next
> >> Next
> >>
> >> The problem is that for each Item I am selecting, I am having to go
> > through
> >> the list to find the value that matches the one I want to set. In this
> >> case, it would have to go through the list 4 times.
> >>
> >> Is there some kind of a way to do it in one line where you say
something
> >> like set the listitem that is equal to my value to selected?
> >>
> >> Thanks,
> >>
> >> Tom
> >>
> >>
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:eOwGcaUOFHA.604@.TK2MSFTNGP10.phx.gbl...
> Seems like a join table is the best way

You lost me on that one.

What I am doing is allowing the user to save different types of searches
based on Job Categorys, Dates, Zip codes etc. They can save this in a
table. One record for each search they want to save. They may want to save
10 different searches so that they don't have to keep putting in all the
different search criteria each time they come back.

One of the search criterea is Job Categories, which they pick from a list
box which as the name of the Job Category as well as the value (which is a
numeric value).

So if they pick 10 different Criteria, I need to store those numbers
somewhere. So I just put the numbers together in a string separated by "|".

When they come back to run another search, they can pick from their stored
searches and I then need to get all the ten (or however many categories
they picked) categories and use them in the search.

Thanks,

Tom
>
> UserId, JobId
> 1,1
> 1,3
> 1,5
> 2,4
> 5,1
> 5,6
> ...
> 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!)
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:OsMYwLUOFHA.2384@.tk2msftngp13.phx.gbl...
>> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
>> wrote in message news:e86j1GUOFHA.1476@.TK2MSFTNGP09.phx.gbl...
>>>> > dim item as ListItem = jobCategories.ITems.FindbyValue(a(j))
>> > if not item is nothing then
>> > item.selected = true
>> > end if
>>>
>> I knew there was a better way.
>>
>>> > Btw, why bother using a relationa database (assuming) if you are gonna
> use
>> > values which are split like that?
>>
>> What I am doing is storing the string in a field that shows which choices
>> the user made to a ListBox (could have many). I am collecting the values
>> and separating them by "|". The Job Categories are themselves in a table
>> ("text and value"). But each user can have many search records (each of
>> which can have a different set of Job Categories). This seemed like the
>> best way to save it.
>>
>> Thanks,
>>
>> Tom
>>> > 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!)
>> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
>> > news:OXpbQjTOFHA.3144@.tk2msftngp13.phx.gbl...
>> >> I have a string that I read from my database: 1|8|5620|541
>> >>
>> >> These are all values in my ListBox. I want to select each of these
> items
>> > (4
>> >> of them - but could be many more). At the moment I am doing the
>> > following:
>> >>
>> >> Dim a() As String
>> >> Dim j As Integer
>> >> a = JobCategoriesSelected.Split("|") ' Where
>> >> JobCategoriesSelected is set to 1|8|5620|541
>> >> For j = 0 To a.GetUpperBound(0)
>> >> trace.warn("string = " & a(j))
>> >> for each item as ListItem in JobCategories.items
>> >> if item.value = a(j) then
>> >> item.selected = true
>> >> end if
>> >> next
>> >> Next
>> >>
>> >> The problem is that for each Item I am selecting, I am having to go
>> > through
>> >> the list to find the value that matches the one I want to set. In
>> >> this
>> >> case, it would have to go through the list 4 times.
>> >>
>> >> Is there some kind of a way to do it in one line where you say
> something
>> >> like set the listitem that is equal to my value to selected?
>> >>
>> >> Thanks,
>> >>
>> >> Tom
>> >>
>> >>
>>>>
>>
Tom:
Not sure how else to explain it...

If user1 can have his search 1 which has job 1, 4, 5 and 6
user 1 can have his search 2 which has jobs 1, 2 and 3

user2 can have her search 1 which has jobs 3

user 7 can have her search 3 which has jobs 1,3
user 7 can have her search 2 which has jobs 4,5

I'd do a table with 3 columns:

UserId, SearchId, JobId
//first case
1, 1, 1
1, 1, 4
1, 1, 5
1, 1, 6
//second case
1,2,1
1,2,2
1,2,3
//third case
2,1,3
//forth case
7,3,1
7,3,3
//fifth case
7,2,4
7,2,5

then when you say, "I want all the jobs for user 7 for the her 3rd saved
search", you do:

select JobId from UserSearchJob
where UserId = 7 and SearchId = 3

and you end up with
1
3

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!)

"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:eurQU4UOFHA.3076@.TK2MSFTNGP12.phx.gbl...
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:eOwGcaUOFHA.604@.TK2MSFTNGP10.phx.gbl...
> > Seems like a join table is the best way
> You lost me on that one.
> What I am doing is allowing the user to save different types of searches
> based on Job Categorys, Dates, Zip codes etc. They can save this in a
> table. One record for each search they want to save. They may want to
save
> 10 different searches so that they don't have to keep putting in all the
> different search criteria each time they come back.
> One of the search criterea is Job Categories, which they pick from a list
> box which as the name of the Job Category as well as the value (which is a
> numeric value).
> So if they pick 10 different Criteria, I need to store those numbers
> somewhere. So I just put the numbers together in a string separated by
"|".
> When they come back to run another search, they can pick from their stored
> searches and I then need to get all the ten (or however many categories
> they picked) categories and use them in the search.
> Thanks,
> Tom
> > UserId, JobId
> > 1,1
> > 1,3
> > 1,5
> > 2,4
> > 5,1
> > 5,6
> > ...
> > 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!)
> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> > news:OsMYwLUOFHA.2384@.tk2msftngp13.phx.gbl...
> >> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> >> wrote in message news:e86j1GUOFHA.1476@.TK2MSFTNGP09.phx.gbl...
> >> >> >> > dim item as ListItem = jobCategories.ITems.FindbyValue(a(j))
> >> > if not item is nothing then
> >> > item.selected = true
> >> > end if
> >> >>
> >> I knew there was a better way.
> >>
> >> >> > Btw, why bother using a relationa database (assuming) if you are
gonna
> > use
> >> > values which are split like that?
> >>
> >> What I am doing is storing the string in a field that shows which
choices
> >> the user made to a ListBox (could have many). I am collecting the
values
> >> and separating them by "|". The Job Categories are themselves in a
table
> >> ("text and value"). But each user can have many search records (each
of
> >> which can have a different set of Job Categories). This seemed like
the
> >> best way to save it.
> >>
> >> Thanks,
> >>
> >> Tom
> >> >> > 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!)
> >> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> >> > news:OXpbQjTOFHA.3144@.tk2msftngp13.phx.gbl...
> >> >> I have a string that I read from my database: 1|8|5620|541
> >> >>
> >> >> These are all values in my ListBox. I want to select each of these
> > items
> >> > (4
> >> >> of them - but could be many more). At the moment I am doing the
> >> > following:
> >> >>
> >> >> Dim a() As String
> >> >> Dim j As Integer
> >> >> a = JobCategoriesSelected.Split("|") ' Where
> >> >> JobCategoriesSelected is set to 1|8|5620|541
> >> >> For j = 0 To a.GetUpperBound(0)
> >> >> trace.warn("string = " & a(j))
> >> >> for each item as ListItem in JobCategories.items
> >> >> if item.value = a(j) then
> >> >> item.selected = true
> >> >> end if
> >> >> next
> >> >> Next
> >> >>
> >> >> The problem is that for each Item I am selecting, I am having to go
> >> > through
> >> >> the list to find the value that matches the one I want to set. In
> >> >> this
> >> >> case, it would have to go through the list 4 times.
> >> >>
> >> >> Is there some kind of a way to do it in one line where you say
> > something
> >> >> like set the listitem that is equal to my value to selected?
> >> >>
> >> >> Thanks,
> >> >>
> >> >> Tom
> >> >>
> >> >>
> >> >> >>
> >>
I thought that was what you meant. The problem is why have all those
records suppose each search option has 15 Job Categories. That's a lot of
records just to handle one field and a lot more work for Sql to do.

Maybe, you are thinking that there is only one field in the record.

Actually, the whole records is:

CREATE TABLE [dbo].[Searches] (
[ClientID] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Email] [varchar] (45) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[SearchID] [int] IDENTITY (1, 1) NOT NULL ,
[SearchName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[KeyWords] [varchar] (80) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[EmailNewJobs] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[EmailNewJobsAddress] [varchar] (45) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[EmailNewJobsFrequency] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[CompanyName] [varchar] (45) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[FullTime] [bit] NULL ,
[PartTime] [bit] NULL ,
[Temporary] [bit] NULL ,
[Contract] [bit] NULL ,
[Seasonal] [bit] NULL ,
[WagesMin] [money] NULL ,
[WagesMax] [money] NULL ,
[WagesType] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ByState] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ByCity] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Miles] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ZipCode] [varchar] (9) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ByKeyword] [bit] NULL ,
[ByDate] [bit] NULL ,
[ByWages] [bit] NULL ,
[ViewBrief] [bit] NULL ,
[ViewDetailed] [bit] NULL ,
[JobCategories] [varchar] (8000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[DatePosted] [datetime] NULL ,
[DateModified] [datetime] NULL
) ON [PRIMARY]

This would mean that if you have 10 Job categories you have 10 identical
records, except for the one field. An awful lot of wasted space (I would
think). Maybe I'm wrong.

I assume you are normalizing the table.

Tom

"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23QE8vnWOFHA.2604@.TK2MSFTNGP10.phx.gbl...
> Tom:
> Not sure how else to explain it...
> If user1 can have his search 1 which has job 1, 4, 5 and 6
> user 1 can have his search 2 which has jobs 1, 2 and 3
> user2 can have her search 1 which has jobs 3
> user 7 can have her search 3 which has jobs 1,3
> user 7 can have her search 2 which has jobs 4,5
>
> I'd do a table with 3 columns:
> UserId, SearchId, JobId
> //first case
> 1, 1, 1
> 1, 1, 4
> 1, 1, 5
> 1, 1, 6
> //second case
> 1,2,1
> 1,2,2
> 1,2,3
> //third case
> 2,1,3
> //forth case
> 7,3,1
> 7,3,3
> //fifth case
> 7,2,4
> 7,2,5
> then when you say, "I want all the jobs for user 7 for the her 3rd saved
> search", you do:
> select JobId from UserSearchJob
> where UserId = 7 and SearchId = 3
> and you end up with
> 1
> 3
> 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!)
>
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:eurQU4UOFHA.3076@.TK2MSFTNGP12.phx.gbl...
>>
>> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
>> wrote in message news:eOwGcaUOFHA.604@.TK2MSFTNGP10.phx.gbl...
>> > Seems like a join table is the best way
>>
>> You lost me on that one.
>>
>> What I am doing is allowing the user to save different types of searches
>> based on Job Categorys, Dates, Zip codes etc. They can save this in a
>> table. One record for each search they want to save. They may want to
> save
>> 10 different searches so that they don't have to keep putting in all the
>> different search criteria each time they come back.
>>
>> One of the search criterea is Job Categories, which they pick from a list
>> box which as the name of the Job Category as well as the value (which is
>> a
>> numeric value).
>>
>> So if they pick 10 different Criteria, I need to store those numbers
>> somewhere. So I just put the numbers together in a string separated by
> "|".
>>
>> When they come back to run another search, they can pick from their
>> stored
>> searches and I then need to get all the ten (or however many categories
>> they picked) categories and use them in the search.
>>
>> Thanks,
>>
>> Tom
>>>> > UserId, JobId
>>> > 1,1
>> > 1,3
>> > 1,5
>> > 2,4
>> > 5,1
>> > 5,6
>>> > ...
>>> > 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!)
>> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
>> > news:OsMYwLUOFHA.2384@.tk2msftngp13.phx.gbl...
>> >> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
>> >> net>
>> >> wrote in message news:e86j1GUOFHA.1476@.TK2MSFTNGP09.phx.gbl...
>> >>> >>> >> > dim item as ListItem = jobCategories.ITems.FindbyValue(a(j))
>> >> > if not item is nothing then
>> >> > item.selected = true
>> >> > end if
>> >>> >>
>> >> I knew there was a better way.
>> >>
>> >>> >> > Btw, why bother using a relationa database (assuming) if you are
> gonna
>> > use
>> >> > values which are split like that?
>> >>
>> >> What I am doing is storing the string in a field that shows which
> choices
>> >> the user made to a ListBox (could have many). I am collecting the
> values
>> >> and separating them by "|". The Job Categories are themselves in a
> table
>> >> ("text and value"). But each user can have many search records (each
> of
>> >> which can have a different set of Job Categories). This seemed like
> the
>> >> best way to save it.
>> >>
>> >> Thanks,
>> >>
>> >> Tom
>> >>> >> > 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!)
>> >> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
>> >> > news:OXpbQjTOFHA.3144@.tk2msftngp13.phx.gbl...
>> >> >> I have a string that I read from my database: 1|8|5620|541
>> >> >>
>> >> >> These are all values in my ListBox. I want to select each of these
>> > items
>> >> > (4
>> >> >> of them - but could be many more). At the moment I am doing the
>> >> > following:
>> >> >>
>> >> >> Dim a() As String
>> >> >> Dim j As Integer
>> >> >> a = JobCategoriesSelected.Split("|") ' Where
>> >> >> JobCategoriesSelected is set to 1|8|5620|541
>> >> >> For j = 0 To a.GetUpperBound(0)
>> >> >> trace.warn("string = " & a(j))
>> >> >> for each item as ListItem in JobCategories.items
>> >> >> if item.value = a(j) then
>> >> >> item.selected = true
>> >> >> end if
>> >> >> next
>> >> >> Next
>> >> >>
>> >> >> The problem is that for each Item I am selecting, I am having to go
>> >> > through
>> >> >> the list to find the value that matches the one I want to set. In
>> >> >> this
>> >> >> case, it would have to go through the list 4 times.
>> >> >>
>> >> >> Is there some kind of a way to do it in one line where you say
>> > something
>> >> >> like set the listitem that is equal to my value to selected?
>> >> >>
>> >> >> Thanks,
>> >> >>
>> >> >> Tom
>> >> >>
>> >> >>
>> >>> >>> >>
>> >>
>>>>
>>
Tshad...
I didn't look at your table. I just wanted to offer an alternative. The old
saying I've used is "Normalize 'til it hurts, denormalize 'til it works".
Your space conerns are certainly valid...and if that's what drove your
design decision, it's very valid. However, unless you can draw from similar
past experience, you typically shouldn't assume. It's far better to start
off with cleaner code and improve it as your testing/profiling indicates,
than start off with an "optimized" version which is less readable and who's
value you never really know.

I have no doubt that your solution, while seemingly very efficient, is far
uglier and difficult to maintain. Not knowing your system, I'll leave it to
you to figure out what tradeoffs are necessary, but I certainly hope that
you'll go through due deligence and not make assumptions. Every day of my
life lately I'm stuck in a world where someone else made decisions based on
assumptions which (a) proved to be uterly flawed and (b) resulted in
millions of dollars worth of code being thrown out.

I certainly don't wish to preach or come off sounding all high and mighty.
But the cost of hard of the extra hard drive room probably equals about 4
hours of your salary....it's pretty obvious which should be the driving
factor between maintainabilty and disk usage...(again, these rules certainly
have valid exceptions...)

Cheers!
Catch you on the flip side (I don't know what that means)

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!)

"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:ei5cfsXOFHA.2928@.TK2MSFTNGP10.phx.gbl...
> I thought that was what you meant. The problem is why have all those
> records suppose each search option has 15 Job Categories. That's a lot of
> records just to handle one field and a lot more work for Sql to do.
> Maybe, you are thinking that there is only one field in the record.
> Actually, the whole records is:
> CREATE TABLE [dbo].[Searches] (
> [ClientID] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [Email] [varchar] (45) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [SearchID] [int] IDENTITY (1, 1) NOT NULL ,
> [SearchName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [KeyWords] [varchar] (80) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [EmailNewJobs] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [EmailNewJobsAddress] [varchar] (45) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL ,
> [EmailNewJobsFrequency] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL ,
> [CompanyName] [varchar] (45) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [FullTime] [bit] NULL ,
> [PartTime] [bit] NULL ,
> [Temporary] [bit] NULL ,
> [Contract] [bit] NULL ,
> [Seasonal] [bit] NULL ,
> [WagesMin] [money] NULL ,
> [WagesMax] [money] NULL ,
> [WagesType] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [ByState] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [ByCity] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Miles] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [ZipCode] [varchar] (9) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [ByKeyword] [bit] NULL ,
> [ByDate] [bit] NULL ,
> [ByWages] [bit] NULL ,
> [ViewBrief] [bit] NULL ,
> [ViewDetailed] [bit] NULL ,
> [JobCategories] [varchar] (8000) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL
> ,
> [DatePosted] [datetime] NULL ,
> [DateModified] [datetime] NULL
> ) ON [PRIMARY]
> This would mean that if you have 10 Job categories you have 10 identical
> records, except for the one field. An awful lot of wasted space (I would
> think). Maybe I'm wrong.
> I assume you are normalizing the table.
> Tom
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%23QE8vnWOFHA.2604@.TK2MSFTNGP10.phx.gbl...
> > Tom:
> > Not sure how else to explain it...
> > If user1 can have his search 1 which has job 1, 4, 5 and 6
> > user 1 can have his search 2 which has jobs 1, 2 and 3
> > user2 can have her search 1 which has jobs 3
> > user 7 can have her search 3 which has jobs 1,3
> > user 7 can have her search 2 which has jobs 4,5
> > I'd do a table with 3 columns:
> > UserId, SearchId, JobId
> > //first case
> > 1, 1, 1
> > 1, 1, 4
> > 1, 1, 5
> > 1, 1, 6
> > //second case
> > 1,2,1
> > 1,2,2
> > 1,2,3
> > //third case
> > 2,1,3
> > //forth case
> > 7,3,1
> > 7,3,3
> > //fifth case
> > 7,2,4
> > 7,2,5
> > then when you say, "I want all the jobs for user 7 for the her 3rd saved
> > search", you do:
> > select JobId from UserSearchJob
> > where UserId = 7 and SearchId = 3
> > and you end up with
> > 1
> > 3
> > 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!)
> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> > news:eurQU4UOFHA.3076@.TK2MSFTNGP12.phx.gbl...
> >>
> >> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> >> wrote in message news:eOwGcaUOFHA.604@.TK2MSFTNGP10.phx.gbl...
> >> > Seems like a join table is the best way
> >>
> >> You lost me on that one.
> >>
> >> What I am doing is allowing the user to save different types of
searches
> >> based on Job Categorys, Dates, Zip codes etc. They can save this in a
> >> table. One record for each search they want to save. They may want to
> > save
> >> 10 different searches so that they don't have to keep putting in all
the
> >> different search criteria each time they come back.
> >>
> >> One of the search criterea is Job Categories, which they pick from a
list
> >> box which as the name of the Job Category as well as the value (which
is
> >> a
> >> numeric value).
> >>
> >> So if they pick 10 different Criteria, I need to store those numbers
> >> somewhere. So I just put the numbers together in a string separated by
> > "|".
> >>
> >> When they come back to run another search, they can pick from their
> >> stored
> >> searches and I then need to get all the ten (or however many
categories
> >> they picked) categories and use them in the search.
> >>
> >> Thanks,
> >>
> >> Tom
> >> >> >> > UserId, JobId
> >> >> > 1,1
> >> > 1,3
> >> > 1,5
> >> > 2,4
> >> > 5,1
> >> > 5,6
> >> >> > ...
> >> >> > 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!)
> >> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> >> > news:OsMYwLUOFHA.2384@.tk2msftngp13.phx.gbl...
> >> >> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
> >> >> net>
> >> >> wrote in message news:e86j1GUOFHA.1476@.TK2MSFTNGP09.phx.gbl...
> >> >> >> >> >> >> > dim item as ListItem = jobCategories.ITems.FindbyValue(a(j))
> >> >> > if not item is nothing then
> >> >> > item.selected = true
> >> >> > end if
> >> >> >> >>
> >> >> I knew there was a better way.
> >> >>
> >> >> >> >> > Btw, why bother using a relationa database (assuming) if you are
> > gonna
> >> > use
> >> >> > values which are split like that?
> >> >>
> >> >> What I am doing is storing the string in a field that shows which
> > choices
> >> >> the user made to a ListBox (could have many). I am collecting the
> > values
> >> >> and separating them by "|". The Job Categories are themselves in a
> > table
> >> >> ("text and value"). But each user can have many search records
(each
> > of
> >> >> which can have a different set of Job Categories). This seemed like
> > the
> >> >> best way to save it.
> >> >>
> >> >> Thanks,
> >> >>
> >> >> Tom
> >> >> >> >> > 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!)
> >> >> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> >> >> > news:OXpbQjTOFHA.3144@.tk2msftngp13.phx.gbl...
> >> >> >> I have a string that I read from my database: 1|8|5620|541
> >> >> >>
> >> >> >> These are all values in my ListBox. I want to select each of
these
> >> > items
> >> >> > (4
> >> >> >> of them - but could be many more). At the moment I am doing the
> >> >> > following:
> >> >> >>
> >> >> >> Dim a() As String
> >> >> >> Dim j As Integer
> >> >> >> a = JobCategoriesSelected.Split("|") ' Where
> >> >> >> JobCategoriesSelected is set to 1|8|5620|541
> >> >> >> For j = 0 To a.GetUpperBound(0)
> >> >> >> trace.warn("string = " & a(j))
> >> >> >> for each item as ListItem in JobCategories.items
> >> >> >> if item.value = a(j) then
> >> >> >> item.selected = true
> >> >> >> end if
> >> >> >> next
> >> >> >> Next
> >> >> >>
> >> >> >> The problem is that for each Item I am selecting, I am having to
go
> >> >> > through
> >> >> >> the list to find the value that matches the one I want to set.
In
> >> >> >> this
> >> >> >> case, it would have to go through the list 4 times.
> >> >> >>
> >> >> >> Is there some kind of a way to do it in one line where you say
> >> > something
> >> >> >> like set the listitem that is equal to my value to selected?
> >> >> >>
> >> >> >> Thanks,
> >> >> >>
> >> >> >> Tom
> >> >> >>
> >> >> >>
> >> >> >> >> >> >>
> >> >>
> >> >> >>
> >>
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:uAezk7XOFHA.2704@.TK2MSFTNGP15.phx.gbl...
> Tshad...
> I didn't look at your table. I just wanted to offer an alternative. The
> old
> saying I've used is "Normalize 'til it hurts, denormalize 'til it works".
> Your space conerns are certainly valid...and if that's what drove your
> design decision, it's very valid. However, unless you can draw from
> similar
> past experience, you typically shouldn't assume. It's far better to
> start
> off with cleaner code and improve it as your testing/profiling indicates,
> than start off with an "optimized" version which is less readable and
> who's
> value you never really know.

Not just space concerns, but that is one of them. I just don't think that
you normalize for normalizing sake (and I know many would disagree - and
there positions are also valid). If I were going to sort this field, I
would agree with you, but it it takes just a couple lines of code to split
out the different numbers versus the amount of space and work for SQL to do
that is really unnecessary (at least in my mind).

Another example of normalization that I would have a problem with would be
phone numbers.

If I have an employee record with 4 phone numbers (home,work,fax and cell),
I would put the phone numbers on the employee record.

Someone else might set up a Phone table with 3 fields

Create table Phone(
PhoneID int,
EmployeeID int,
PhoneType int,
PhoneNumber)

Then you would need a table for Phone types:

Create Table PhoneTypes(
PhoneType int,
PhoneDescription)

A little much, if you ask me.
> I have no doubt that your solution, while seemingly very efficient, is far
> uglier and difficult to maintain. Not knowing your system, I'll leave it
> to
> you to figure out what tradeoffs are necessary, but I certainly hope that
> you'll go through due deligence and not make assumptions. Every day of
> my
> life lately I'm stuck in a world where someone else made decisions based
> on
> assumptions which (a) proved to be uterly flawed and (b) resulted in
> millions of dollars worth of code being thrown out.

As you say, efficient. And easy to maintain.

I agree on decision that need to be made. And these need to be made based
on valid assumptions. And you're right, many times you have to make changes
as assumptions change. That can happen to valid assumptions, as well.

There are no guarantees and you can't assume that things won't change.

We just finished a discussion on code/behind/beside/inside models (I don't
want to get into the discussion again as that was pretty well hashed out).
There were various reasons for each and all valid based on the situation.
But I feel you are making a mistake to stick strictly to a model just for
the models sake, if it doesn't fit the situation. Asp.net 2.0 may change
the way code/behind is used for a lot of people who use (and swear by it)
now.

> I certainly don't wish to preach or come off sounding all high and mighty.
> But the cost of hard of the extra hard drive room probably equals about 4
> hours of your salary....it's pretty obvious which should be the driving
> factor between maintainabilty and disk usage...(again, these rules
> certainly
> have valid exceptions...)

I have no problem with your opinion. I learn a lot listening to everyones
opinion. It helps me shape mine. Sometimes it changes mine, other times
(even if the opinion is opposite of mine) it will reinforce mine.

I was told once that if you have to know the rules and then break them,
that's one thing.
To not know the rules and break them is just ignorance.

Tom.

> Cheers!
> Catch you on the flip side (I don't know what that means)
> 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!)
>
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:ei5cfsXOFHA.2928@.TK2MSFTNGP10.phx.gbl...
>> I thought that was what you meant. The problem is why have all those
>> records suppose each search option has 15 Job Categories. That's a lot
>> of
>> records just to handle one field and a lot more work for Sql to do.
>>
>> Maybe, you are thinking that there is only one field in the record.
>>
>> Actually, the whole records is:
>>
>> CREATE TABLE [dbo].[Searches] (
>> [ClientID] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
>> ,
>> [Email] [varchar] (45) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>> [SearchID] [int] IDENTITY (1, 1) NOT NULL ,
>> [SearchName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>> [KeyWords] [varchar] (80) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
>> ,
>> [EmailNewJobs] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>> [EmailNewJobsAddress] [varchar] (45) COLLATE
>> SQL_Latin1_General_CP1_CI_AS
>> NULL ,
>> [EmailNewJobsFrequency] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS
>> NULL ,
>> [CompanyName] [varchar] (45) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>> [FullTime] [bit] NULL ,
>> [PartTime] [bit] NULL ,
>> [Temporary] [bit] NULL ,
>> [Contract] [bit] NULL ,
>> [Seasonal] [bit] NULL ,
>> [WagesMin] [money] NULL ,
>> [WagesMax] [money] NULL ,
>> [WagesType] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>> [ByState] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>> [ByCity] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>> [Miles] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>> [ZipCode] [varchar] (9) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>> [ByKeyword] [bit] NULL ,
>> [ByDate] [bit] NULL ,
>> [ByWages] [bit] NULL ,
>> [ViewBrief] [bit] NULL ,
>> [ViewDetailed] [bit] NULL ,
>> [JobCategories] [varchar] (8000) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL
>> ,
>> [DatePosted] [datetime] NULL ,
>> [DateModified] [datetime] NULL
>> ) ON [PRIMARY]
>>
>> This would mean that if you have 10 Job categories you have 10 identical
>> records, except for the one field. An awful lot of wasted space (I would
>> think). Maybe I'm wrong.
>>
>> I assume you are normalizing the table.
>>
>> Tom
>>
>> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
>> wrote in message news:%23QE8vnWOFHA.2604@.TK2MSFTNGP10.phx.gbl...
>> > Tom:
>> > Not sure how else to explain it...
>>> > If user1 can have his search 1 which has job 1, 4, 5 and 6
>> > user 1 can have his search 2 which has jobs 1, 2 and 3
>>> > user2 can have her search 1 which has jobs 3
>>> > user 7 can have her search 3 which has jobs 1,3
>> > user 7 can have her search 2 which has jobs 4,5
>>>> > I'd do a table with 3 columns:
>>> > UserId, SearchId, JobId
>> > //first case
>> > 1, 1, 1
>> > 1, 1, 4
>> > 1, 1, 5
>> > 1, 1, 6
>> > //second case
>> > 1,2,1
>> > 1,2,2
>> > 1,2,3
>> > //third case
>> > 2,1,3
>> > //forth case
>> > 7,3,1
>> > 7,3,3
>> > //fifth case
>> > 7,2,4
>> > 7,2,5
>>> > then when you say, "I want all the jobs for user 7 for the her 3rd
>> > saved
>> > search", you do:
>>> > select JobId from UserSearchJob
>> > where UserId = 7 and SearchId = 3
>>> > and you end up with
>> > 1
>> > 3
>>> > 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!)
>>>> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
>> > news:eurQU4UOFHA.3076@.TK2MSFTNGP12.phx.gbl...
>> >>
>> >> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
>> >> net>
>> >> wrote in message news:eOwGcaUOFHA.604@.TK2MSFTNGP10.phx.gbl...
>> >> > Seems like a join table is the best way
>> >>
>> >> You lost me on that one.
>> >>
>> >> What I am doing is allowing the user to save different types of
> searches
>> >> based on Job Categorys, Dates, Zip codes etc. They can save this in a
>> >> table. One record for each search they want to save. They may want
>> >> to
>> > save
>> >> 10 different searches so that they don't have to keep putting in all
> the
>> >> different search criteria each time they come back.
>> >>
>> >> One of the search criterea is Job Categories, which they pick from a
> list
>> >> box which as the name of the Job Category as well as the value (which
> is
>> >> a
>> >> numeric value).
>> >>
>> >> So if they pick 10 different Criteria, I need to store those numbers
>> >> somewhere. So I just put the numbers together in a string separated
>> >> by
>> > "|".
>> >>
>> >> When they come back to run another search, they can pick from their
>> >> stored
>> >> searches and I then need to get all the ten (or however many
> categories
>> >> they picked) categories and use them in the search.
>> >>
>> >> Thanks,
>> >>
>> >> Tom
>> >>> >>> >> > UserId, JobId
>> >>> >> > 1,1
>> >> > 1,3
>> >> > 1,5
>> >> > 2,4
>> >> > 5,1
>> >> > 5,6
>> >>> >> > ...
>> >>> >> > 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!)
>> >> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
>> >> > news:OsMYwLUOFHA.2384@.tk2msftngp13.phx.gbl...
>> >> >> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
>> >> >> net>
>> >> >> wrote in message news:e86j1GUOFHA.1476@.TK2MSFTNGP09.phx.gbl...
>> >> >>> >> >>> >> >> > dim item as ListItem = jobCategories.ITems.FindbyValue(a(j))
>> >> >> > if not item is nothing then
>> >> >> > item.selected = true
>> >> >> > end if
>> >> >>> >> >>
>> >> >> I knew there was a better way.
>> >> >>
>> >> >>> >> >> > Btw, why bother using a relationa database (assuming) if you are
>> > gonna
>> >> > use
>> >> >> > values which are split like that?
>> >> >>
>> >> >> What I am doing is storing the string in a field that shows which
>> > choices
>> >> >> the user made to a ListBox (could have many). I am collecting the
>> > values
>> >> >> and separating them by "|". The Job Categories are themselves in a
>> > table
>> >> >> ("text and value"). But each user can have many search records
> (each
>> > of
>> >> >> which can have a different set of Job Categories). This seemed
>> >> >> like
>> > the
>> >> >> best way to save it.
>> >> >>
>> >> >> Thanks,
>> >> >>
>> >> >> Tom
>> >> >>> >> >> > 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!)
>> >> >> > "tshad" <tscheiderich@.ftsolutions.com> wrote in message
>> >> >> > news:OXpbQjTOFHA.3144@.tk2msftngp13.phx.gbl...
>> >> >> >> I have a string that I read from my database: 1|8|5620|541
>> >> >> >>
>> >> >> >> These are all values in my ListBox. I want to select each of
> these
>> >> > items
>> >> >> > (4
>> >> >> >> of them - but could be many more). At the moment I am doing the
>> >> >> > following:
>> >> >> >>
>> >> >> >> Dim a() As String
>> >> >> >> Dim j As Integer
>> >> >> >> a = JobCategoriesSelected.Split("|") ' Where
>> >> >> >> JobCategoriesSelected is set to 1|8|5620|541
>> >> >> >> For j = 0 To a.GetUpperBound(0)
>> >> >> >> trace.warn("string = " & a(j))
>> >> >> >> for each item as ListItem in JobCategories.items
>> >> >> >> if item.value = a(j) then
>> >> >> >> item.selected = true
>> >> >> >> end if
>> >> >> >> next
>> >> >> >> Next
>> >> >> >>
>> >> >> >> The problem is that for each Item I am selecting, I am having to
> go
>> >> >> > through
>> >> >> >> the list to find the value that matches the one I want to set.
> In
>> >> >> >> this
>> >> >> >> case, it would have to go through the list 4 times.
>> >> >> >>
>> >> >> >> Is there some kind of a way to do it in one line where you say
>> >> > something
>> >> >> >> like set the listitem that is equal to my value to selected?
>> >> >> >>
>> >> >> >> Thanks,
>> >> >> >>
>> >> >> >> Tom
>> >> >> >>
>> >> >> >>
>> >> >>> >> >>> >> >>
>> >> >>
>> >>> >>> >>
>> >>
>>>>
>>