1

我有一个编辑页面,我在其中根据从数据库返回的值设置 radcombobox (rcb_ParentCompany) 的选定索引。但是,在回发时,组合框中的文本会不断更改为数据集中的顶部项目。任何想法为什么?

protected void Page_Load(object sender, EventArgs e)
    {
         if (IsPostBack)
         {
             BindOperatingNameComboBox(rcb_OperatingName);
             BindParentCompanyComboBox(rcb_ParentCompany);
         }
    }



protected void btn_Edit_Command(object sender, CommandEventArgs e)
    {
        Client ClientToEdit = ClientController.ViewClient(int.Parse(e.CommandArgument.ToString()));

        //Populate Client fields
        txt_ClientName.Text = ClientToEdit.ClientName;
        rcb_OperatingName.Text = ClientToEdit.OperatingName;
        int ParentCompanyIndex = rcb_ParentCompany.FindItemIndexByValue(ClientToEdit.ParentCompanyID.ToString());
        rcb_ParentCompany.SelectedIndex = ParentCompanyIndex;
        txt_Address1.Text = ClientToEdit.Address1;
        txt_Address2.Text = ClientToEdit.Address2;
        txt_Country.Text = ClientToEdit.Country;
        txt_Region.Text = ClientToEdit.Region;
        txt_City.Text = ClientToEdit.City;
        txt_PostalCode.Text = ClientToEdit.PostalCode;
        txt_ClientNote.Text = ClientToEdit.ClientNote;

        tbl_EditServices.Controls.Clear();
        PopulateEditClientPanel(ClientToEdit);

        btn_SaveChanges.CommandArgument = e.CommandArgument.ToString();
        btn_Cancel.CommandArgument = e.CommandArgument.ToString();
    }



protected void BindParentCompanyComboBox(RadComboBox ComboBox)
    {
        DataTable OperatingNames = ClientController.GetExistingClientAndOperatingNames("");
        ComboBox.DataTextField = "ClientName";
        ComboBox.DataValueField = "ClientID";
        ComboBox.DataSource = OperatingNames;
        ComboBox.DataBind();
    }



protected void rcb_ParentCompany_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        BindParentCompanyComboBox((sender as RadComboBox));
    }
4

1 回答 1

1

任何想法为什么?

是的,因为你正在做if(IsPostBack)而不是if(!IsPostBack)

于 2012-08-01T17:52:57.937 回答