Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Web DropDownList set to next date

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gsauns - 23 Aug 2007 22:19 GMT
Hello,

I have an ASP.NET app with a DropDownList on the page, which is bound
to values from a table. I have a Repeater control on the page whose
displayed data is dependent on the DropDownList value selected by the
user. (The DataTextField is a Datetime concatenated with a string).

On the Page_Load event, if it's not a postback, I would like the
DropDownList to programmatically be set to the next occurring day in
the DropDownList (the date values are in the table in fairly regular
weekly intervals). For example, if today is 8/23/07, I would like,
upon opening the page, the DropDownList to select 8/25/07 (if that is
the next occurring day in the data) and display the appropriate data
below.

I'm having no luck... any help?
-Here's my ASP.NET code for the controls:

<asp:SqlDataSource ID="sqldsDayList" runat="server" ConnectionString="<
%$ ConnectionStrings:ConnectionStringNew %>"
SelectCommand="SELECT [key], CONVERT(varchar(10), [day_dt], 1) + ' - '
+ [day_cd] As Day FROM [Table]"></asp:SqlDataSource>

<asp:DropDownList ID="ddlDaySelect" runat="server"
DataSourceID="sqldsDayList" DataTextField="Day" DataValueField="key"
AutoPostBack="true">
</asp:DropDownList>

<!--- For the repeater: -->
<asp:SqlDataSource ID="sqldsCreds" runat="server" ConnectionString="<%
$ ConnectionStrings:ConnectionStringNew %>"
SelectCommand="SELECT * FROM Credit">
</asp:SqlDataSource>

<asp:Repeater ID="rptrCredListing" runat="server"
DataSourceID="sqldsCreds">

-And now the C# code for my ddlDaySelect.OnSelectedIndexChanged:

sqldsCreds.SelectCommand = "SELECT Credit.*, Type.credit_type AS
credit_type FROM Credit, Type WHERE Credit.ctype_id = Type.ctype_id
AND key=" + ddlDaySelect.SelectedValue AND created = '" +
(string)Session["Username"] + "'";
Tim Van Wassenhove - 24 Aug 2007 15:23 GMT
> I have an ASP.NET app with a DropDownList on the page, which is bound
> to values from a table. I have a Repeater control on the page whose
> displayed data is dependent on the DropDownList value selected by the
> user. (The DataTextField is a Datetime concatenated with a string).

At which time is the databinding performed? At the Page_Load event?
In that case you may want to read http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Vie
wstate.aspx

to get a better unstanding.

Signature

Kind regards,
Tim Van Wassenhove <url:http://www.timvw.be/>

gsauns - 24 Aug 2007 16:48 GMT
On Aug 24, 10:23 am, Tim Van Wassenhove <ti...@newsgroup.nospam>
wrote:

> > I have an ASP.NET app with a DropDownList on the page, which is bound
> > to values from a table. I have a Repeater control on the page whose
[quoted text clipped - 8 lines]
> Kind regards,
> Tim Van Wassenhove <url:http://www.timvw.be/>

Thanks. Yea the data source is set in the control's declaration and is
not changed at all. I will read the entire article when I have time,
Tim Van Wassenhove - 24 Aug 2007 21:21 GMT
> On Aug 24, 10:23 am, Tim Van Wassenhove <ti...@newsgroup.nospam>
> wrote:
[quoted text clipped - 14 lines]
> Thanks. Yea the data source is set in the control's declaration and is
> not changed at all. I will read the entire article when I have time,

A possible 'shortcut' is to add the control and bind it in the Page_Init
eventhandler...

Signature

Kind regards,
Tim Van Wassenhove <url:http://www.timvw.be/>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.