这行将所选索引设置为正确的数字:

    ddlCliNewMsg.SelectedIndex = ddlCliNewMsg.Items.IndexOf(ddlCliNewMsg.Items.FindByValue(dr["ClientText"].ToString()));


但是,当加载弹出窗口时,将选择0索引。

最佳答案

更改

    if (dr["ClientText"].ToString().Length > 0)
    {
    ddlCliNewMsg.SelectedValue = dr["ClientText"].ToString();
    }




    if (dr["ClientText"].ToString().Length > 0)
    {
    ddlCliNewMsg.ClearSelection(); //making sure the previous selection has been cleared
    ddlCliNewMsg.Items.FindByValue(dr["ClientText"].ToString()).Selected = true;
    }

10-02 13:39