回调后无法在服务器端获取值

本文关键字:服务器端 获取 回调 | 更新日期: 2024-10-31 17:38:14

我已经通过回调动态填充了我的复选框列表,如下所示:

    <dx:ASPxComboBox ID="ASPxComboBox_Prot" runat="server" DataSourceID="SqlDataSource_Prot"
                     TextField="LIBELLE" ValueField="NO_PROT" ValueType="System.Int32">
        <ClientSideEvents SelectedIndexChanged="function(s, e) { cbp_ProtOrdos.PerformCallback(s.GetValue());}" />
    </dx:ASPxComboBox>
</td>
</tr>
</table>
<dx:ASPxCallbackPanel ID="ASPxCallbackPanel_ProtOrdo" runat="server"
                      ClientInstanceName="cbp_ProtOrdos" OnCallback="cbp_ProtOrdo_Callback">
    <PanelCollection>
        <dx:PanelContent>
            <dx:ASPxCheckBoxList ID="CheckBoxList_Ordo" runat="server" ClientInstanceName="CheckBoxList_Ordo" ValueType="System.Int32" TextField="LIBELLE" ValueField="NO_ORDO">
            </dx:ASPxCheckBoxList>
            <dx:ASPxButton ID="ASPxButton_ProtOrdoGen" runat="server"
                           Text="Générer ordonnance & Planifier pour infirmier"
                           OnClick="ASPxButton_ProtOrdoGen_Click"  
                           EnableDefaultAppearance="false" BackColor="Yellow"  CssClass="bt" Theme="BlackGlass" ForeColor="Black">
            </dx:ASPxButton>
        </dx:PanelContent>
    </PanelCollection>
</dx:ASPxCallbackPanel>

在服务器端代码:

 protected void cbp_ProtOrdo_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
    {
        var panel = sender as ASPxCallbackPanel;
        var cblist = panel.FindControl("CheckBoxList_Ordo") as ASPxCheckBoxList;
        cblist.DataSource = Outils.Get_ProtOrdo(ASPxComboBox_Prot.Value.ToString());
        cblist.DataBind();
    }

它工作正常,但现在我想获取用户已检查的值。所以我添加了按钮来做到这一点。

protected void ASPxButton_ProtOrdoGen_Click(object sender, EventArgs e)
{
    //TabPage oPage = ASPxPageControl_DosSoin.TabPages.FindByName("Surveillance");
    //ASPxPanel oPanel = (ASPxPanel)oPage.FindControl("ASPxPanel_ListSurveil");
    //ASPxRoundPanel oRoundPnl = (ASPxRoundPanel)oPanel.FindControl("ASPxRoundPanel_ProtOrdo");
    //ASPxCallbackPanel ocbpPanel = (ASPxCallbackPanel)oRoundPnl.FindControl("ASPxCallbackPanel_ProtOrdo");
    //ASPxCheckBoxList cblist = (ASPxCheckBoxList)ocbpPanel.FindControl("CheckBoxList_Ordo") as ASPxCheckBoxList;
    List<string> selectItems_Ordo = new List<string>();
    foreach (var oItem in CheckBoxList_Ordo.Items)
    {
        ListEditItem oNewChk = (ListEditItem)oItem;
        if (oNewChk.Selected)
        {                
            selectItems_Ordo.Add( oNewChk.Value.ToString());
        }
    }
    foreach (var oItem in selectItems_Ordo)
    {
        if (DossierDuSoins.check_doublon_ordo(oItem.ToString(), Soin_Id) == 0)
            DossierDuSoins.RamenerVal(DossierDuSoins.GetLibOrdo(oItem.ToString()), Soin_Id, oItem.ToString());
    }
    string TempId = "";
    if (selectItems_Ordo.Count == 0)
    {
        lbl_err.Text = "Pas de médicament de sélectionné";
    }
    else
    {
        foreach (string selectItemId in selectItems_Ordo)
        {
            if (TempId != "")
                TempId += ",";
            TempId += selectItemId.ToString();
        }
        string AdrUrl = "Print_Ordo.aspx?SoinId=" + Soin_Id + "&SelId=" + TempId;
            ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", AdrUrl));
    }
}

问题是我无法获得我的检查值。那是因为回发会破坏我动态构建的所有复选框列表吗?

回调后无法在服务器端获取值

尝试此操作,而不是使用 var 来选择复选框列表

foreach (ListItem yourItem in YourCheckBoxList.Items)
    {
        if (item.Selected)
        {
            // If the item is selected, Add to your list/ save to DB
        }
        else
        {
            // If item is not selected, do something else.
        }
    }