我在UserControl中有以下dropdwonlists;
<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>
我正在使用以下代码在page_load事件上为它们分配值;
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();
这是下拉列表生成的标记;
<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>
<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>
当页面加载并从下拉列表中选择一些内容时,我试图从后面的代码中获取selectedvalue,但所选值与所选值不同。
你怎么知道这里发生了什么?答案 0 :(得分:5)
将代码放在以下条件语句中的Page_Load
方法中:
if (!Page.IsPostBack)
{
}