DropDownList.SelectedValue is not correct
I have following dropdwonlists in a UserControl;
<span class="src-engine-row-title-span">ADT : </span>
<asp:DropDownList runat="server" ID="ddlAdultTrf"></asp:DropDownList>
<span class="src-engine-row-title-span">CHD : </span>
<asp:DropDownList runat="server" ID="ddlChildrenTrf"></asp:DropDownList>
<span class="src-engine-row-title-span">INF : </span>
<asp:DropDownList runat="server" ID="ddlInfantTrf"></asp:DropDownList>
and I am assigning values to them on page_load event with following code;
ddlAdultTrf.DataTextField = "FieldName";
ddlAdultTrf.DataValueField = "FieldValue";
ddlAdultTrf.DataSource = repo.AdultsForTransferSearch();
ddlAdultTrf.DataBind();
ddlInfantTrf.DataTextField = "FieldName";
ddlInfantTrf.DataValueField = "FieldValue";
ddlInfantTrf.DataSource = repo.ChildrenForTransferSearch();
ddlInfantTrf.DataBind();
ddlChildrenTrf.DataTextField = "FieldName";
ddlChildrenTrf.DataValueField = "FieldValue";
ddlChildrenTrf.DataSource = repo.InfantsForTransferSearch();
ddlChildrenTrf.DataBind();
here is the generated markup for the dropdownlists;
<span class="src-engine-row-title-span">ADT : </span>
<select name="ctl00$MainContent$SearchEngine$ddlAdultTrf" id="MainContent_SearchEngine_ddlAdultTrf">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="32">32</option>
<option value="33">33</option>
开发者_JAVA百科 <option value="34">34</option>
<option value="35">35</option>
<option value="36">36</option>
<option value="37">37</option>
<option value="38">38</option>
<option value="39">39</option>
<option value="40">40</option>
</select>
<span class="src-engine-row-title-span">CHD : </span>
<select name="ctl00$MainContent$SearchEngine$ddlChildrenTrf" id="MainContent_SearchEngine_ddlChildrenTrf">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<span class="src-engine-row-title-span">INF : </span>
<select name="ctl00$MainContent$SearchEngine$ddlInfantTrf" id="MainContent_SearchEngine_ddlInfantTrf">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
when the page is loaded and I select something from the dropdownlist, I am trying to get the selectedvalue from code behind but the selected value is not the same with the selected one.
do u have any idea what is going on here?
Place the code in the Page_Load
method inside the following conditional statement:
if (!Page.IsPostBack)
{
}
精彩评论