Saturday, March 24, 2012
populate FormView fields from a DropDownList
I'm trying to build an online form using asp.net and vb.net for the
code behind in Visual Studio 2005.
I want to fill 3 fields in a FormView that's connected to one table
(table1) with information from another table (table2) by choosing the
key field from table2 in a DropDownList.
Table2 has 3 fields with info that doesn't change (name, phone# and
email for about 5 customer service reps). I want each rep to choose
their name in the DropDownList to populate those fields in the
FormView.
I'm connecting to the sql db with an ObjectDataSource.
I'm thinking I just need to put some VB code into the
SelectedIndexChanged event of the ddl, something like:
*something goes here* = DropDownList1.SelectedValue.ToString()
But I'm drawing a blank on what would go to the left of the equal
sign.
Thanks in advance for the help.myFormView.FindControl("myControlId") will find the control if it is in the
template the formview is going to present. Otherwise you may need to do
something like myFormView.EditItemTemplate.FindControl("myControlId").
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"mkidd" <michaelk@.volkcorp.com> wrote in message
news:19842b1a-bab5-4594-aaef-c1cf99efd809@.u10g2000prn.googlegroups.com...
> Hi,
> I'm trying to build an online form using asp.net and vb.net for the
> code behind in Visual Studio 2005.
> I want to fill 3 fields in a FormView that's connected to one table
> (table1) with information from another table (table2) by choosing the
> key field from table2 in a DropDownList.
> Table2 has 3 fields with info that doesn't change (name, phone# and
> email for about 5 customer service reps). I want each rep to choose
> their name in the DropDownList to populate those fields in the
> FormView.
> I'm connecting to the sql db with an ObjectDataSource.
> I'm thinking I just need to put some VB code into the
> SelectedIndexChanged event of the ddl, something like:
> *something goes here* = DropDownList1.SelectedValue.ToString()
> But I'm drawing a blank on what would go to the left of the equal
> sign.
> Thanks in advance for the help.
Thanks, but can you help me with what to do to write the data from the
DropDownList table to the FormView after the FindControl event? I'm
really new at this.
On Jan 14, 9:15 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.org> wrote:
> myFormView.FindControl("myControlId") will find the control if it is in th
e
> template the formview is going to present. Otherwise you may need to do
> something like myFormView.EditItemTemplate.FindControl("myControlId").
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
> "mkidd" <micha...@.volkcorp.com> wrote in message
> news:19842b1a-bab5-4594-aaef-c1cf99efd809@.u10g2000prn.googlegroups.com...
>
>
>
>
>
>
>
>
>
Friday, March 16, 2012
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