Web DropDownList set to next date

  • Thread starter Thread starter gsauns
  • Start date Start date
G

gsauns

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
"></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"] + "'";
 
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-Viewstate.aspx
to get a better unstanding.
 
At which time is the databinding performed? At the Page_Load event?
In that case you may want to readhttp://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Unders...
to get a better unstanding.

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,
 
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...
 
Back
Top