English 中文(简体)
ASP.NET DropDown 未保留关于后退的选定项目清单
原标题:ASP.NET DropDownList not retaining selected item on postback

我有一个人手工艺协会,在“Load”活动页上,在我选择了一个项目后,对选定的项目进行了清理,并且选择了DroopDownList的第一个项目。 (D.R.D.R.D.R.D.R.D.R.R.D.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.(D.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.(S.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R.R

if (!IsPostBack)
{
    List<Country> lCountries = new List<Country>();
    List<CompanySchedule> lCompanySchedules = new List<CompanySchedule>();
    this.Load_Countries(lCountries);
    this.Load_Schedules(lCompanySchedules);
    if (personnelRec == null) 
    { 
        personnelRec = new Personnel(); 
    }
    if (Request.QueryString["UA"] != null && Convert.ToInt32(Request.QueryString["UA"].ToString()) > 0)
    {
        userAccount.ID = Convert.ToInt32(Request.QueryString["UA"].ToString());
        App_Database.Snapshift_Select_Helper.SNAPSHIFT_SELECT_PERSONNEL_APP_ACCOUNT(ref userAccount);
    }

    this.imgEmployeePicture.ImageUrl = "./images/Employees/nophoto.gif";
    if (Request.QueryString["EI"] != null && Convert.ToInt32(Request.QueryString["EI"].ToString()) > 0)
    {
            this.Load_PersonnelRec(Convert.ToInt32(Request.QueryString["EI"].ToString()));
    }
    else
    {
        this.lblChangeDirectionHead.Enabled = false;
        this.lblChangeDirections.Enabled = false;
        this.lbSchedules.Disabled = true;
    }
}
最佳回答

网页生命周期如下(加上与贵问题无关的其他步骤):

  1. OnInit
  2. Populate controls from ViewState (during postback)
  3. Set the selected values (during postback)
  4. Page_Load

你们需要使观点国能够把清单填入“选择”该项目。 在此情况下,确保你不重新加入第_页,失去选定的价值。 见if(!IsPostback){/ Populate }

否则,你必须按每页要求将名单人工填入。 <代码>Page_Load在生命周期过晚,因此选定项目丢失。

<><>Edit>:

<代码>DropDownList也必须有有效数值(与浏览器中显示的案文不同)。 这项工作通过<代码>DataValue Field房地产进行。 每一数值必须是独一无二的,否则将只选定第一个重复项目。 如果你在浏览器中看到超文本来源的话,你应当:

<select>
    <option value="unique_value1">Displayed text1</option>
    <option value="unique_value2">Displayed text2</option>
</select>

独特的数值用于在服务器上选择正确的项目。

问题回答

是否使用主页? 如果是的话,会记得在主页上写了《意见》。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签