capture value from dropdownlist where the display dropdownlist is not default
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
i want to capture selected date on my dropdown list, where there 5 day will display on dropdownlist. im usually put default value on dropdown, but not this time because in drop down list i want it always display current daya and next 5 day. but i dont know how to capture the data.
<asp:DropDownList ID="ddldate" runat="server">
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
protected void Button1_Click(object sender, EventArgs e)
string deliverytime = ddldate.SelectedValue.ToString();
lbltest.Text = deliverytime;
c# asp.net
add a comment |Â
up vote
6
down vote
favorite
i want to capture selected date on my dropdown list, where there 5 day will display on dropdownlist. im usually put default value on dropdown, but not this time because in drop down list i want it always display current daya and next 5 day. but i dont know how to capture the data.
<asp:DropDownList ID="ddldate" runat="server">
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
protected void Button1_Click(object sender, EventArgs e)
string deliverytime = ddldate.SelectedValue.ToString();
lbltest.Text = deliverytime;
c# asp.net
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
i want to capture selected date on my dropdown list, where there 5 day will display on dropdownlist. im usually put default value on dropdown, but not this time because in drop down list i want it always display current daya and next 5 day. but i dont know how to capture the data.
<asp:DropDownList ID="ddldate" runat="server">
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
protected void Button1_Click(object sender, EventArgs e)
string deliverytime = ddldate.SelectedValue.ToString();
lbltest.Text = deliverytime;
c# asp.net
i want to capture selected date on my dropdown list, where there 5 day will display on dropdownlist. im usually put default value on dropdown, but not this time because in drop down list i want it always display current daya and next 5 day. but i dont know how to capture the data.
<asp:DropDownList ID="ddldate" runat="server">
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
protected void Button1_Click(object sender, EventArgs e)
string deliverytime = ddldate.SelectedValue.ToString();
lbltest.Text = deliverytime;
c# asp.net
c# asp.net
asked 1 hour ago
Ariff Naj
507
507
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
You're repopulating the DropDownList
for every postback and reloading the page, hence SelectedValue
property value may be different from posted value. Just put a check against IsPostBack
to prevent repopulating DropDownList
data on postback:
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
thx,, i miss look at that
â Ariff Naj
24 mins ago
add a comment |Â
up vote
5
down vote
You should not bind data on PostaBack
, change your FormLoad
code to below sample:
protected void Page_Load(object sender, EventArgs e)
if(!Page.IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
If you check the PostBack
property as condition, your SelectedValue
will keep, otherwise DropDown
will bind on each page-post.
And I also recommend you to check SelectedValue
status before use it, don't try to get value if this null
, check the following code:
protected void Button1_Click(object sender, EventArgs e)
if(ddldate.SelectedValue != null)
string deliverytime = ddldate.SelectedValue.ToString();
lbltest.Text = deliverytime;
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You're repopulating the DropDownList
for every postback and reloading the page, hence SelectedValue
property value may be different from posted value. Just put a check against IsPostBack
to prevent repopulating DropDownList
data on postback:
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
thx,, i miss look at that
â Ariff Naj
24 mins ago
add a comment |Â
up vote
3
down vote
accepted
You're repopulating the DropDownList
for every postback and reloading the page, hence SelectedValue
property value may be different from posted value. Just put a check against IsPostBack
to prevent repopulating DropDownList
data on postback:
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
thx,, i miss look at that
â Ariff Naj
24 mins ago
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You're repopulating the DropDownList
for every postback and reloading the page, hence SelectedValue
property value may be different from posted value. Just put a check against IsPostBack
to prevent repopulating DropDownList
data on postback:
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
You're repopulating the DropDownList
for every postback and reloading the page, hence SelectedValue
property value may be different from posted value. Just put a check against IsPostBack
to prevent repopulating DropDownList
data on postback:
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
answered 51 mins ago
Tetsuya Yamamoto
12.5k41839
12.5k41839
thx,, i miss look at that
â Ariff Naj
24 mins ago
add a comment |Â
thx,, i miss look at that
â Ariff Naj
24 mins ago
thx,, i miss look at that
â Ariff Naj
24 mins ago
thx,, i miss look at that
â Ariff Naj
24 mins ago
add a comment |Â
up vote
5
down vote
You should not bind data on PostaBack
, change your FormLoad
code to below sample:
protected void Page_Load(object sender, EventArgs e)
if(!Page.IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
If you check the PostBack
property as condition, your SelectedValue
will keep, otherwise DropDown
will bind on each page-post.
And I also recommend you to check SelectedValue
status before use it, don't try to get value if this null
, check the following code:
protected void Button1_Click(object sender, EventArgs e)
if(ddldate.SelectedValue != null)
string deliverytime = ddldate.SelectedValue.ToString();
lbltest.Text = deliverytime;
add a comment |Â
up vote
5
down vote
You should not bind data on PostaBack
, change your FormLoad
code to below sample:
protected void Page_Load(object sender, EventArgs e)
if(!Page.IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
If you check the PostBack
property as condition, your SelectedValue
will keep, otherwise DropDown
will bind on each page-post.
And I also recommend you to check SelectedValue
status before use it, don't try to get value if this null
, check the following code:
protected void Button1_Click(object sender, EventArgs e)
if(ddldate.SelectedValue != null)
string deliverytime = ddldate.SelectedValue.ToString();
lbltest.Text = deliverytime;
add a comment |Â
up vote
5
down vote
up vote
5
down vote
You should not bind data on PostaBack
, change your FormLoad
code to below sample:
protected void Page_Load(object sender, EventArgs e)
if(!Page.IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
If you check the PostBack
property as condition, your SelectedValue
will keep, otherwise DropDown
will bind on each page-post.
And I also recommend you to check SelectedValue
status before use it, don't try to get value if this null
, check the following code:
protected void Button1_Click(object sender, EventArgs e)
if(ddldate.SelectedValue != null)
string deliverytime = ddldate.SelectedValue.ToString();
lbltest.Text = deliverytime;
You should not bind data on PostaBack
, change your FormLoad
code to below sample:
protected void Page_Load(object sender, EventArgs e)
if(!Page.IsPostBack)
List<ListItem> items = new List<ListItem>();
for (int i = 0; i < 5; i++)
items.Add(new ListItem(DateTime.Now.AddDays(i).ToShortDateString(), DateTime.Now.AddDays(i).ToShortDateString()));
ddldate.DataSource = items;
ddldate.DataBind();
ddldate.Items[0].Selected = true;
If you check the PostBack
property as condition, your SelectedValue
will keep, otherwise DropDown
will bind on each page-post.
And I also recommend you to check SelectedValue
status before use it, don't try to get value if this null
, check the following code:
protected void Button1_Click(object sender, EventArgs e)
if(ddldate.SelectedValue != null)
string deliverytime = ddldate.SelectedValue.ToString();
lbltest.Text = deliverytime;
answered 58 mins ago
Siavash Ghanbari
1,232920
1,232920
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53076426%2fcapture-value-from-dropdownlist-where-the-display-dropdownlist-is-not-default%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password