Thursday, March 29, 2012
Pop Up?
error message in a dialog box.
But I found it only works with IE, Not Netscape.
Did someone have it work ever?
Thanks.Hi,
Validations got server and client side validation. When you browse your
pages in Netscape they use the server-side validation and not the
client-side validation as the client side Validation scripts only works
only with IE.
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Monday, March 26, 2012
Populate A Dropdown From Another Dropdown
(Just when I think I understand how "postback" works, I find I'm wrong again!)
I have the dropdown set to autopostback=true. When the user selects a choice in this dropdown, the page postsback (I think) and I want it to then query another table in the same database to fill the second dropdown list AND keep the original dropdown list's selection.
For some reason, I can get it to fill the original dropdown, but then when it postsback, I get an error because my SQL statement to load the second dropdown looks like this:
Dim objSeriesDA As New OleDb.OleDbDataAdapter("SELECT * FROM Series WHERE fldProviderID=" & lstProvider.SelectedItem.Value & " ORDER BY fldSeriesNumber DESC", objSeriesCN)
Apparently, when the page postsback, the original dropdown list loses its selection, causing the SQL statement above to error out on a null reference.
Any ideas?
If need be, I can throw this up on a server so you all can see what I'm talking about... I can post the full source as well.
Thanks!
HWKY
:)wrap the code that is filling your first drop down list with this:
If Not Page.IsPostBack Then
'...your code here.
End If
Does anyone have a link to some information that explains PostBack in depth?
well, this link (http://www.15seconds.com/Issue/020102.htm) helped me with some basics on the page lifecycle when i was having user control postback problems. Really, there's not much more to the kind of postback stuff in your first post. If you know how the page loads and when control events are evaluated, that's pretty much it. Were you looking for information on how to roll your own PostBack handler or something else?
Populate a label with text from a drop down list box
I'm trying to grab the text that appears in a drop down list server control
and place it in a label server control on the same page. I can get the
selected value, that's easy. But I want the text.
Thanksddl.SelectedItem.Text
Eliyahu
"Mardy" <Mardy@.discussions.microsoft.com> wrote in message
news:983E0BF1-2741-4B22-920F-6F7708CA712B@.microsoft.com...
> I know this is probably real easy but I can't figure it out.
> I'm trying to grab the text that appears in a drop down list server
control
> and place it in a label server control on the same page. I can get the
> selected value, that's easy. But I want the text.
> Thanks
>
Populate a label with text from a drop down list box
I'm trying to grab the text that appears in a drop down list server control
and place it in a label server control on the same page. I can get the
selected value, that's easy. But I want the text.
Thanksddl.SelectedItem.Text
Eliyahu
"Mardy" <Mardy@.discussions.microsoft.com> wrote in message
news:983E0BF1-2741-4B22-920F-6F7708CA712B@.microsoft.com...
> I know this is probably real easy but I can't figure it out.
> I'm trying to grab the text that appears in a drop down list server
control
> and place it in a label server control on the same page. I can get the
> selected value, that's easy. But I want the text.
> Thanks
Populate asp:label with text from db and retain formatting?
Av.
"Tony" <anonymous@dotnet.itags.org.discussions.microsoft.com> wrote in message
news:7B9C3796-02D8-4180-AD93-8572746CD951@dotnet.itags.org.microsoft.com...
> Hello,
> Im can't seem to figure this out OR find any documentation on if it's
> possible; I need to populate the value of an asp:label with text retrieved
> from the database. However when the text is populated I need to retain
> carriage returns and indents that the text contains. That way if I want to
> see this:
> Some text with a manual
> carriage return.
> 1. this is one.
> 2. this is two.
> It doesn't look like this:
> Some text with a manual carriage return. 1. this is one. 2. this is two.
> I've tried enclosing the text in <pre></pre> tags before the text is
> assigned to the label and it works fine except for 2 things. The text is
> rendered in a non-styled font and in the instance that the user entered
> really long text and didn't manullay hit a carriage return- which causes
> the text continue to the right instead of automatically wrapping even
> though I define a width on my label, the cell the label is within, etc..
> Does anyone know how to get this to work? I must have looked around on the
> net for hours!TextMode is not a property for a label but a textbox. I have tried using a textbox control with this property set to multiline previously however without specifically setting the height of the textbox I end up with vertical scrollbars- which I cannot have because this is for a printable report.
populate datagrid from listbox value
the value in the listbox I need to then populate a datagrid with detailed
information for the highlighted row.
How can i do that?Try this?
ASP.NET: Master/Detail View using a DropDownList and a DataGrid
[url]http://authors.aspalliance.com/aldotnet/examples/masterdetail_ddl_datagrid.aspx[/u
rl]
"Mike" <me@.me.com> wrote in message
news:ORHOgJWXEHA.2364@.TK2MSFTNGP12.phx.gbl...
>I have to populate a list box from a db table and when the user clicks on
> the value in the listbox I need to then populate a datagrid with detailed
> information for the highlighted row.
> How can i do that?
>
populate datagrid from listbox value
the value in the listbox I need to then populate a datagrid with detailed
information for the highlighted row.
How can i do that?Try this?
ASP.NET: Master/Detail View using a DropDownList and a DataGrid
http://authors.aspalliance.com/aldo...l_datagrid.aspx
"Mike" <me@.me.com> wrote in message
news:ORHOgJWXEHA.2364@.TK2MSFTNGP12.phx.gbl...
>I have to populate a list box from a db table and when the user clicks on
> the value in the listbox I need to then populate a datagrid with detailed
> information for the highlighted row.
> How can i do that?
Saturday, March 24, 2012
Populate Month in Combobox <Resolved>
I have a asp.net control combo box. I want to pouplate it with the name of the months.
I am wring the code in the code behind. I am using vb.net as the code behind.
My code is
'Month
dim i as integer
dim myvar as string
i = 1
Do While i <= 12
myvar = MonthName(i, True)
cboMonth.Items.Add(myvar)
i = i + 1
Loop
I get the populated month names in the combobox, because of the function month name.
But in the value I want 1,2,3 not Jan, Feb, Mar...How to achive this.
Had been it ASP I wud have written:
do while iLoop <= 12
myvar = MonthName(iLoop,true)
Response.Write "<option value=" & iLoop & " selected>" & myvar & "</option>"
iLoop = i Loop+1
loop
This wud have given me the dsired result.
How to do in VB.NET?With a bit of R&D got the solution:
i = 1
Do While i <= 12
myvar = MonthName(i, True)
cboToMonth.Items.Add(New ListItem(myvar, i))
i = i + 1
Loop
populate text box from sql
Wednesday, March 21, 2012
Populate textbox with textmode=password
ThanksWrite a code behind for this for text change event to change to * from test..
Nor text box has a property of password...
Cheers,
Devendra Naik
It's be design.. but there is a way around it.. instead of changing the Text property, you can do this:
myTextBox.Attributes["value"] = "somethingfromthedatabase";
Populating a check boxlist with info from a database
I have a dropdown box with the value titleid. I also have a checkboxlist with the value of classificationid. How do I populate a checkboxlist when I change the selection in the dropdown?
I have this on pageload
Checkboxlist1.datasource="mystoredprocedure"
checkboxlist1.datatextfield = "description"
checkboxlist1.datavaluefield = "classificationid"
Checkboxlist.databind()
If checkboxlist1.items[i].value = "1' then
checkboxlist1.items[i].selected = true
else
checkboxlist1.items[i].selected = false
Do I need to put something in here to connect/bind to the dropdown box?
You need to handle the "SelectedIndexChanged" event of the dropdown, This event is raised when the selectedItem changes. Please also remember to set the "AutoPostBack" property of the dropdwn to true.
<asp:DropDownListID="DropDownList1"AutoPostBack="true"runat="server"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"/>
protectedvoid DropDownList1_SelectedIndexChanged(object sender,EventArgs e)
{
//Bind the check box list here again and add any necessary logic you want might want
}s
If this helps please remember to mark post as answer.
Help I'm confused...
I have this as my dropdown:<asp:DropDownListID="DropDownList1"runat="server"DataSourceID="SqlDataSource1"
DataTextField="Title"DataValueField="TitleID"AutoPostBack="True"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList><br/><asp:CheckBoxListID="CheckBoxList1"runat="server"DataSourceID="SqlDataSource2"
DataTextField="description"DataValueField="classificationid"RepeatColumns="5"RepeatDirection="Horizontal"BorderStyle="Dashed"CellPadding="2"CellSpacing="2"Height="247px"Width="762px"BorderColor="#CFB37D">
</asp:CheckBoxList><br/>
What do I put on the code behind page for the SelectedIndexChange to bring back the items in the database? If the titleID is selected I want check marks in the checkboxes (classificationid) to show what the user has selected already. Please help!
ProtectedSub CheckBoxList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles CheckBoxList1.SelectedIndexChangedEndSub
Okay I've figured some things out... Here's my stored procedure:
CREATE Procedure GetClassID
@.titleid int
AS
SELECT
classifications.[description], titleclassification.classificationid
FROM
classifications inner join titleclassification on titleclassification.classificationid = classifications.classificationid
wheretitleid=@.titleid
GO
I'm trying to code the checkboxlist and having problems
ProtectedSub CheckBoxList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles CheckBoxList1.SelectedIndexChangedDim iAsInteger
Dim chkbxAs CheckBoxListFor i = 0To chkbx.Items.Count - 1
Next
if chkbx.Items[i].SelectedValuethen
CheckBoxList1.Items([i].selected =True)Else
CheckBoxList1.Items([i].selected =False)EndIf
CheckBoxList1.DataBind()EndSub
what am I doing wrong?
Ok, i want to understand one thing. Based on which field do you want the items to be checked? You have 2 fields in your select SP, you need to have a third one and based on it, you set the the items to be checked or not.
I want the classificationid field to be checked. What's the other field to add and how do I set the items to be checked or not? Do I need a Boolean?
if your sql database classificationid field is set to 'bit' you wont need to do anything except checkboxlist1.databind()
it knows 1's are checks and vice versa.
edit: ok so you are using stored procedures. ive never done it that way. what i would do, which is pretty simple imo, is create a fresh checkbox list. let it create a sqldatasource for it. i use the nice little sql generator thing when i create it. select the 2 columns from your database. click the where button and use the control selected index thing. i hope im not being to vague. then lastly you will have to set the dropdownlist to autopostback.
Okay I tried it your way and got the same thing as my stored procedure but how do I get the items to be checked? What do I put for the codebehind
ProtectedSub CheckBoxList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles CheckBoxList1.SelectedIndexChanged
That's where I'm lost.
its not checkbox1 seletedindexchanged, its dropdownlist1 selectedindex changed. in that code snippet just put checkboxlist1.databind(). when a checkbox list is bound to a bit field, it will check the boxes that are true
please post your most recent aspx page code so i can look at your sqldatasource.
I can't change my classificationid field to a bit field because it will change the entire structure of my database. Ugh. Do I write a function like so to convert to a bit. Is this one okay.
CREATE FUNCTION [Converttobool]
(@.value char(1))
RETURNS bit
BEGIN
declare @.returnvalue bit
if @.value = 'y'
set @.returnvalue = 1
else
set @.returnvalue= 0
return @.returnvalue
END
i think you can just do it in your select statement
cast(columnname, bit)
This is what I have thus far it brings back my items from the database but it's not checked, any ideas?
ProtectedSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList1.SelectedIndexChangedDim iAsInteger
For i = 0To CheckBoxList1.Items.Count - 1If (CheckBoxList1.Items(i).Selected)Then
Response.Write(CheckBoxList1.Items(i).Value)
EndIf
Next
EndSub
you dont need to manually check anything if youve databound it to the sqldatasource... its just checkboxlist1.databind()
Added it cast to my select statement
SELECT
classifications.[description], cast(titleclassification.classificationid as bit)
FROM
classifications inner join titleclassification on titleclassification.classificationid = classifications.classificationid
wheretitleid=@.titleid
Now I'm getting ...Databinding: System.Data.DataRowView does not contain a property with the name classificationid. Any suggestions?
Okay I got rid of the databinding error message, page comes up but still no items are checked? I'm going. I feel that I'm almost there any suggestions?
Here's my select statement:
SELECT
classifications.[description], cast(titleclassification.classificationid as bit)
FROM
classifications inner join titleclassification on titleclassification.classificationid = classifications.classificationid
wheretitleid=@.titleid
What do I put here?
ProtectedSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList1.SelectedIndexChangedCheckBoxList1.DataBind()
EndSubThanks if anyone can assist me!
populating a drop down box with ms access information
dim ConnString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyDBPath;"
dim conn As System.Data.OleDb.OleDbConnection(ConnString)
dim cmd As New OleDb.OleDbCommand()
dim dr as OleDb.OleDbDataReader
cmd.connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select id, name from mytable"
try
conn.open
dr = cmd.executereader() 'assuming dr is your datareader
myDropDownList.datasource = dr
myDropDownList.DataTextField = "name"
myDropDownList.DataValueField = "id" 'example of assinging a value field too
myDropDownList.Databind()
finally
conn.close
end try
This is an example using a datareader for quick access and ideal for dropdownlists. You will see examples using datasets too but this just happens to be my preference from a performance point of view.
Populating a dropdown box
Hi all,
I have populated one dropdown menu using data from a database using the following code
Sub Page_Load (seander as Object, e as EventArgs) Year.DataSource = GetYear() Year.DataBind()End Sub Function GetYear() As System.Data.SqlClient.SqlDataReader Dim connectionString As String = "server='localhost'; user id='sa'; password='eoyson'; Database='PupilRoll'" Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString) Dim queryString As String = "SELECT [Years].* FROM [Years]" Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection) sqlConnection.Open Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection) Return dataReader End Function
I am now trying to populate another dropdown list depending on the information selected from the previous dropdown list.
Cheers!
Try the tutorial right on this site:
Master Detail Filtering with Two Dropdownlists
populating a dropdown list from arraylist of objects
i have an arraylist which holds my Customer object, that contains the
customer details, but when i try binding it to a dropdown box, i cant get
the values to appear..
this is what i tried:
customerList.DataSource = Customer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = CType(customerList.DataSource,
Customer).Email.ToString
customerList.DataValueField = CType(customerList.DataSource,
Customer).CustomerID.ToString
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
this error returns me a invalid cast error..so i also tried the normal
method:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
but this populates the dropdown list with the the values
"Web2004.Customer" - which is my application namespace.Object...'
any help appreciated,
Paul.Rearrange the order of your code:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.DataBind()
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
"Paul M" <milsnips@.hotmail.com> wrote in message
news:uf9aWLvQEHA.3568@.TK2MSFTNGP10.phx.gbl...
> hi there,
> i have an arraylist which holds my Customer object, that contains the
> customer details, but when i try binding it to a dropdown box, i cant get
> the values to appear..
> this is what i tried:
> customerList.DataSource = Customer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = CType(customerList.DataSource,
> Customer).Email.ToString
> customerList.DataValueField = CType(customerList.DataSource,
> Customer).CustomerID.ToString
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
> this error returns me a invalid cast error..so i also tried the normal
> method:
>
> customerList.DataSource = DotcoCustomer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = "email"
> customerList.DataValueField = "customerID"
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
>
> but this populates the dropdown list with the the values
> "Web2004.Customer" - which is my application namespace.Object...'
> any help appreciated,
> Paul.
>
>
populating a dropdown list from arraylist of objects
i have an arraylist which holds my Customer object, that contains the
customer details, but when i try binding it to a dropdown box, i cant get
the values to appear..
this is what i tried:
customerList.DataSource = Customer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = CType(customerList.DataSource,
Customer).Email.ToString
customerList.DataValueField = CType(customerList.DataSource,
Customer).CustomerID.ToString
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
this error returns me a invalid cast error..so i also tried the normal
method:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
but this populates the dropdown list with the the values
"Web2004.Customer" - which is my application namespace.Object...??
any help appreciated,
Paul.Rearrange the order of your code:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.DataBind()
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
"Paul M" <milsnips@.hotmail.com> wrote in message
news:uf9aWLvQEHA.3568@.TK2MSFTNGP10.phx.gbl...
> hi there,
> i have an arraylist which holds my Customer object, that contains the
> customer details, but when i try binding it to a dropdown box, i cant get
> the values to appear..
> this is what i tried:
> customerList.DataSource = Customer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = CType(customerList.DataSource,
> Customer).Email.ToString
> customerList.DataValueField = CType(customerList.DataSource,
> Customer).CustomerID.ToString
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
> this error returns me a invalid cast error..so i also tried the normal
> method:
>
> customerList.DataSource = DotcoCustomer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = "email"
> customerList.DataValueField = "customerID"
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
>
> but this populates the dropdown list with the the values
> "Web2004.Customer" - which is my application namespace.Object...??
> any help appreciated,
> Paul.
Friday, March 16, 2012
Populating a List Box
Hi
I am trying to populate a list box with all my themes that i have created but I keep getting an message which is
Type DirectoryInfo is not defined i m guessing i have to declare if but i dont know how are where please could you guys help. Thanks
1Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)23If (Not Page.IsPostBack)Then45 Dim themeDirAs New DirectoryInfo(Server.MapPath("App_Themes"))6 lstThemes.DataTextField ="Name"7 lstThemes.DataSource = themeDir.GetDirectories()8 lstThemes.DataBind()910End If1112 End Sub13The DirectoryInfo class is located under the System.IO namespace.
Yeah i tired declaring it as Inherits System.IO. Is that the correct appraoch
hello i ve tried to use the system io like u suggested but i still have the same problem here s my code. Do u have any ideas where i am going wrong cheers
PartialClass _Default
Inherits System.Web.UI.Page
Inherits System.IO
ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)
If (Not Page.IsPostBack)Then
Dim themeDirAsNew DirectoryInfo(Server.MapPath("App_Themes"))lstThemes.DataTextField ="Name"
lstThemes.DataSource = themeDir.GetDirectories()
lstThemes.DataBind()
EndIf
EndSub
EndClass
Is your App_Thems directory in your web directory? I would check the path returned by Server.MapPath("App_Theme"), perhaps it doesn't exists and that's why you're getting an error.
bigyawn_hippo:
hello i ve tried to use the system io like u suggested but i still have the same problem here s my code. Do u have any ideas where i am going wrong cheers
PartialClass _DefaultInherits System.Web.UI.Page
Inherits System.IO
ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)
If (Not Page.IsPostBack)Then
Dim themeDirAsNew DirectoryInfo(Server.MapPath("App_Themes"))lstThemes.DataTextField ="Name"
lstThemes.DataSource = themeDir.GetDirectories()
lstThemes.DataBind()
EndIf
EndSubEndClass
Hi,
Based on my understanding, you want to import the System.IO namespace in your asp.net VB application. If I have misunderstood you, please feel free to let me know.
The DirectoryInfo class is in the System.IO. If we want to use it, we can import it. For example:
Imports System.IOPartialClass _DefaultInherits System.Web.UI.PageProtected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)If (Not Page.IsPostBack)Then Dim themeDirAs New DirectoryInfo(Server.MapPath("App_Themes")) lstThemes.DataTextField ="Name" lstThemes.DataSource = themeDir.GetDirectories() lstThemes.DataBind()End If End SubEnd Class Alternatively, we can use this namespace in the code behind directly, for example:
Dim themeDir As NewSystem.IO.DirectoryInfo(Server.MapPath("App_Themes"))
Besides, you can find more information about asp.net by the following link:http://www.asp.net/get-started/.
I hope this helps.
Hi hyppo,
why don't you try to put only this two instructions ?
lstThemes.DataSource = themeDir.GetDirectories()
lstThemes.DataBind()
I found my code doing the same and i didn' t write ...DataTextField
Populating a List box with recent dates
Services department. We collect data from recent grads. I am
recreating the online survey we use. I am trying to populate the
graduation date with 4 dates. May **, June **, August **, December **.
The "**" represents the year of graduation. To prevent having to
constantly update this survey I'd like to dynamically create this
values. So at page load I want it to check the server time and only
show the months from the past year. IE since Today is June 07 the
values would read June 07, May 07, December 06, August 06. Then in
August It would read August 07, June 07, May 07, December 06. Etc... I
am trying to think of a clever way to do this and just can not do
this. Anyone have an idea?"djjohnst" <djjohnst@.gmail.comwrote in message
news:1180703317.389866.199290@.p77g2000hsh.googlegr oups.com...
Quote:
Originally Posted by
Anyone have an idea?
List<DateTimelstDates = new List<DateTime>();
DateTime dtmStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart);
}
dtmStart = dtmStart.AddMonths(-1);
}
--
http://www.markrae.net
How about something like...
DateTime dt = DateTime.Today();
for (int iLoop = 0; iLoop < 4; iLoop++)
{
ddlMyDropDown.Items.Add(new ListItem(String.Format("{0:MMM yy}",
dt)));
dt = dt.DateAdd("MM", -3, dt);
}
Dunc
http://www.fluidfoundation.com
On 1 Jun, 14:08, djjohnst <djjoh...@.gmail.comwrote:
Quote:
Originally Posted by
I am having a interesting issue. I work for a University's Career
Services department. We collect data from recent grads. I am
recreating the online survey we use. I am trying to populate the
graduation date with 4 dates. May **, June **, August **, December **.
The "**" represents the year of graduation. To prevent having to
constantly update this survey I'd like to dynamically create this
values. So at page load I want it to check the server time and only
show the months from the past year. IE since Today is June 07 the
values would read June 07, May 07, December 06, August 06. Then in
August It would read August 07, June 07, May 07, December 06. Etc... I
am trying to think of a clever way to do this and just can not do
this. Anyone have an idea?
On Jun 1, 3:25 pm, "Mark Rae" <m...@.markNOSPAMrae.netwrote:
Quote:
Originally Posted by
"djjohnst" <djjoh...@.gmail.comwrote in message
>
news:1180703317.389866.199290@.p77g2000hsh.googlegr oups.com...
>
Quote:
Originally Posted by
Anyone have an idea?
>
List<DateTimelstDates = new List<DateTime>();
DateTime dtmStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart);
}
dtmStart = dtmStart.AddMonths(-1);
>
}
>
--http://www.markrae.net
Well done, Mark!
"Alexey Smirnov" <alexey.smirnov@.gmail.comwrote in message
news:1180705293.175856.189800@.u30g2000hsc.googlegr oups.com...
Quote:
Originally Posted by
Well done, Mark!
LOL!
--
http://www.markrae.net
"Dunc" <duncan.welch@.gmail.comwrote in message
news:1180705084.782217.124280@.g4g2000hsf.googlegro ups.com...
Quote:
Originally Posted by
DateTime dt = DateTime.Today();
>
for (int iLoop = 0; iLoop < 4; iLoop++)
{
ddlMyDropDown.Items.Add(new ListItem(String.Format("{0:MMM yy}",
dt)));
dt = dt.DateAdd("MM", -3, dt);
}
Suppose you start today, what are the four dates which your code will add to
the DropDownList...?
--
http://www.markrae.net
Just a bit of modification to Mark's code to output it as djjohnst was looking
for, in the "June XX" format):
List<StringlstDates = new List<String>();
DateTime dtmStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart.ToString("MMMM yy"));
}
dtmStart = dtmStart.AddMonths(-1);
}
ddlGradDates.DataSource = lstDates;
ddlGradDates.DataBind();
- Converted it from a list collection of DateTimes to Strings; maybe a KVP
to keep the "data" and presentation apart may be a solution if the two need
to be different.
- Added the MMMM yy to output the long Month name and short year.
HTH.
-dl
--
David R. Longnecker
Web Developer
http://blog.tiredstudent.com
Quote:
Originally Posted by
"djjohnst" <djjohnst@.gmail.comwrote in message
news:1180703317.389866.199290@.p77g2000hsh.googlegr oups.com...
>
Quote:
Originally Posted by
>Anyone have an idea?
>>
List<DateTimelstDates = new List<DateTime>();
DateTime dtmStart = new DateTime(DateTime.Now.Year,
DateTime.Now.Month, 1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart);
}
dtmStart = dtmStart.AddMonths(-1);
}
"David Longnecker" <dlongnecker@.community.nospamwrote in message
news:463c247119638c972440ba448a4@.msnews.microsoft. com...
Quote:
Originally Posted by
Just a bit of modification to Mark's code to output it as djjohnst was
looking for, in the "June XX" format):
True enough - I took the final formatting "as read", and assumed that the
it was the actual date generation that was causing the OP problems... :-)
--
http://www.markrae.net
As of today i would want it to display the following options
June 07
May 07
Dec 06
August 06
"djjohnst" <djjohnst@.gmail.comwrote in message
news:1180712937.354039.273110@.q69g2000hsb.googlegr oups.com...
Quote:
Originally Posted by
As of today i would want it to display the following options
June 07
May 07
Dec 06
August 06
Yes, I know...
--
http://www.markrae.net
Forgive me. I am really new to ASP.net. Where would i put that code? I
tried in the Head section and it did not work.
"djjohnst" <djjohnst@.gmail.comwrote in message
news:1180717365.236048.170310@.q75g2000hsh.googlegr oups.com...
Quote:
Originally Posted by
Forgive me. I am really new to ASP.net. Where would i put that code? I
tried in the Head section and it did not work.
The code I gave you is C#, which runs server-side so it can't go in your
page's header section...
Are you using in-line server-side code or code-behind...?
--
http://www.markrae.net
in-line. Do you think it would be better to do code behind?
"djjohnst" <djjohnst@.gmail.comwrote in message
news:1180721754.964410.217790@.m36g2000hse.googlegr oups.com...
Quote:
Originally Posted by
in-line.
OK.
Quote:
Originally Posted by
Do you think it would be better to do code behind?
Wouldn't make the slightest difference...
--
http://www.markrae.net
Populating a List box with recent dates
Services department. We collect data from recent grads. I am
recreating the online survey we use. I am trying to populate the
graduation date with 4 dates. May **, June **, August **, December **.
The "**" represents the year of graduation. To prevent having to
constantly update this survey I'd like to dynamically create this
values. So at page load I want it to check the server time and only
show the months from the past year. IE since Today is June 07 the
values would read June 07, May 07, December 06, August 06. Then in
August It would read August 07, June 07, May 07, December 06. Etc... I
am trying to think of a clever way to do this and just can not do
this. Anyone have an idea?"djjohnst" <djjohnst@.gmail.com> wrote in message
news:1180703317.389866.199290@.p77g2000hsh.googlegroups.com...
> Anyone have an idea?
List<DateTime> lstDates = new List<DateTime>();
DateTime dtmStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart);
}
dtmStart = dtmStart.AddMonths(-1);
}
http://www.markrae.net
How about something like...
DateTime dt = DateTime.Today();
for (int iLoop = 0; iLoop < 4; iLoop++)
{
ddlMyDropDown.Items.Add(new ListItem(String.Format("{0:MMM yy}",
dt)));
dt = dt.DateAdd("MM", -3, dt);
}
Dunc
http://www.fluidfoundation.com
On 1 Jun, 14:08, djjohnst <djjoh...@.gmail.com> wrote:
> I am having a interesting issue. I work for a University's Career
> Services department. We collect data from recent grads. I am
> recreating the online survey we use. I am trying to populate the
> graduation date with 4 dates. May **, June **, August **, December **.
> The "**" represents the year of graduation. To prevent having to
> constantly update this survey I'd like to dynamically create this
> values. So at page load I want it to check the server time and only
> show the months from the past year. IE since Today is June 07 the
> values would read June 07, May 07, December 06, August 06. Then in
> August It would read August 07, June 07, May 07, December 06. Etc... I
> am trying to think of a clever way to do this and just can not do
> this. Anyone have an idea?
On Jun 1, 3:25 pm, "Mark Rae" <m...@.markNOSPAMrae.net> wrote:
> "djjohnst" <djjoh...@.gmail.com> wrote in message
> news:1180703317.389866.199290@.p77g2000hsh.googlegroups.com...
>
> List<DateTime> lstDates = new List<DateTime>();
> DateTime dtmStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)
;
> while (lstDates.Count < 4)
> {
> if (dtmStart.Month == 5
> || dtmStart.Month == 6
> || dtmStart.Month == 8
> || dtmStart.Month == 12)
> {
> lstDates.Add(dtmStart);
> }
> dtmStart = dtmStart.AddMonths(-1);
> }
> --http://www.markrae.net
Well done, Mark!
"Alexey Smirnov" <alexey.smirnov@.gmail.com> wrote in message
news:1180705293.175856.189800@.u30g2000hsc.googlegroups.com...
> Well done, Mark!
LOL!
http://www.markrae.net
"Dunc" <duncan.welch@.gmail.com> wrote in message
news:1180705084.782217.124280@.g4g2000hsf.googlegroups.com...
> DateTime dt = DateTime.Today();
> for (int iLoop = 0; iLoop < 4; iLoop++)
> {
> ddlMyDropDown.Items.Add(new ListItem(String.Format("{0:MMM yy}",
> dt)));
> dt = dt.DateAdd("MM", -3, dt);
> }
Suppose you start today, what are the four dates which your code will add to
the DropDownList...?
http://www.markrae.net
Just a bit of modification to Mark's code to output it as djjohnst was looki
ng
for, in the "June XX" format):
List<String> lstDates = new List<String>();
DateTime dtmStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart.ToString("MMMM yy"));
}
dtmStart = dtmStart.AddMonths(-1);
}
ddlGradDates.DataSource = lstDates;
ddlGradDates.DataBind();
- Converted it from a list collection of DateTimes to Strings; maybe a KVP
to keep the "data" and presentation apart may be a solution if the two need
to be different.
- Added the MMMM yy to output the long Month name and short year.
HTH.
-dl
David R. Longnecker
Web Developer
http://blog.tiredstudent.com
> "djjohnst" <djjohnst@.gmail.com> wrote in message
> news:1180703317.389866.199290@.p77g2000hsh.googlegroups.com...
>
> List<DateTime> lstDates = new List<DateTime>();
> DateTime dtmStart = new DateTime(DateTime.Now.Year,
> DateTime.Now.Month, 1);
> while (lstDates.Count < 4)
> {
> if (dtmStart.Month == 5
> || dtmStart.Month == 6
> || dtmStart.Month == 8
> || dtmStart.Month == 12)
> {
> lstDates.Add(dtmStart);
> }
> dtmStart = dtmStart.AddMonths(-1);
> }
"David Longnecker" <dlongnecker@.community.nospam> wrote in message
news:463c247119638c972440ba448a4@.msnews.microsoft.com...
> Just a bit of modification to Mark's code to output it as djjohnst was
> looking for, in the "June XX" format):
True enough - I took the final formatting "as read", and assumed that the
it was the actual date generation that was causing the OP problems... :-)
http://www.markrae.net
As of today i would want it to display the following options
June 07
May 07
Dec 06
August 06
"djjohnst" <djjohnst@.gmail.com> wrote in message
news:1180712937.354039.273110@.q69g2000hsb.googlegroups.com...
> As of today i would want it to display the following options
> June 07
> May 07
> Dec 06
> August 06
Yes, I know...
http://www.markrae.net
Populating a list box from a loop
I was wondering how you would populate a listbox in asp.net with values from an array created by a loop.
here is the loop structure I am using:
Public Sub Page_Load()
Dim MyString, MyArray, Msg
Dim i as integer
Dim AddThis as string
MyString=BillDS.FieldValue("Week Reason 1", nothing)
MyArray=Split(MyString, "F", -1, vbTextCompare)
Msg=MyArray(0)
For i = 1 To UBound(MyArray)
Msg=Msg & "," & MyArray(i)
Next
lblReasonforError.Text=Msg
End Sub
I can get it to populate the first value in the array but I need it to populate all the values in the array which will vary according to the record it is looking at. Then with those value(s) I want to populate a listbox with all the error codes that are stored in a table on sql server according to the results of the split.
For example:
tblErrorCodes
Code ErrorMessage
1 Wrong
2 Bad
Split gets the value of 1 and 2
Populate listbox like so:
Wrong
Bad
Hope this is clear
Thank you
http://aspnet.4guysfromrolla.com/articles/082504-1.aspx
Hope that helps
uncleb wrote:
You can simply bind datalist to an array by setting the array as the datasource of the datalist
It's the simplest and the only way since ListBox doesn't have Add method.
Madmaxrtw,I'm not sure what your code is about.
But in case you need to use just some items you'd have to transform array into another one.
Or might be use DataTextField and DataValueField properties.
Hey guys I got it here is the loop script
<script language="VB" runat="server">
Public Sub Page_Load()
Dim MyString, MyArray, Msg
Dim i as integer
Dim AddThis as string
MyString=BillDS.FieldValue("Week Reason 1", nothing)
MyArray=Split(MyString, "F", -1, vbTextCompare)
Msg=MyArray(0)
For i = 1 To UBound(MyArray)
Msg=Msg & "," & MyArray(i)
Next
dlErrorList.DataSource=MyArray
dlErrorList.DataBind()
End Sub
</script>
And the DataList:
<asp:datalist CellPadding="10" ID="dlErrorList" RepeatColumns="0"
RepeatDirection="Vertical" runat="server" gridline="Both">
<ItemTemplate>
<b><%# Container.DataItem %></b>
</ItemTemplate>
</asp:datalist>
Thank you so MUCH!!!
Yakov72 wrote:
It's the simplest and the only way since ListBox doesn't have Add method.
Yes it does.
You add to the ListBox Items array. Not directly to the ListBox.
BobT wrote:
Yes it does.
You add to the ListBox Items array. Not directly to the ListBox.
You're right.
Thank you for corrections.
populating a list box by alphabetical surname
I have a listbox contianing strings which ahs been populated from a databsae via "SELECT * FROM researchers"
i.e
John Doe www.johndoe.com
David Allen www.daveallen.com
Andrew Rodgers www.andrewdavidson.com
..
I need this to be displayed as
David Allen www.daveallen.com
John Doe www.johndoe.com
Andrew Rodgers www.andrewdavidson.com
i.e alphabetically by surname?
How do I do this?SELECT * FROM researchers ORDER BY LastName ASC