设置index为0后如何刷新下拉列表?



我已经为生成excel报告的按钮创建了一个事件处理程序。(ExportExcel(filename);是生成excel报告的方法,仅供参考)所以这很好。我现在要做的是刷新下拉列表,让它反映正确的下拉选择是什么。

我让它将下拉列表设置为第0个索引,但由于某种原因下拉列表没有改变。我想我需要单独重置下拉列表。下面是一些代码。(我留下了一些注释和Debug.WriteLine()来展示我的思考过程)

protected void GenerateButton1(object sender, EventArgs e)
{
// CustomerDropdown.ClearSelection();
// CustomerDropdown.Items.Clear();
// Page.Response.Redirect(Page.Request.Url.ToString(), true);
//////////
// Below is resetting the CustomerDropdown list.
ViewState["DropDownIndexSelection"] = CustomerDropdown.SelectedItem.Value.Trim();
DataSet dataSet = (DataSet)ViewState["DropDownListDs"];
var filename = "Customer ID - " + DateTime.Now + ".xlsx";
ExportExcel(filename);
// DataSet DropDownIndexSelection = (DataSet)ViewState["DropDownIndexSelection"];
CustomerDropdown.Items.Clear();
// CustomerDropdown.ClearSelection();
CustomerDropdown.DataTextField = dataSet.Tables[0].Columns["cust_id"].ToString();
CustomerDropdown.DataValueField = dataSet.Tables[0].Columns["cust_id"].ToString();
CustomerDropdown.DataSource = dataSet.Tables[0];  //assigning datasource to the dropdownlist  
// CustomerDropdown.Items[0].Selected = true;
CustomerDropdown.DataBind();  //binding dropdownlist 
CustomerDropdown.Items.Insert(0, new ListItem("Please select"));
CustomerDropdown.Items.Insert(1, new ListItem("All"));
CustomerDropdown.Items.FindByValue("Please select").Selected = true;
Debug.WriteLine(CustomerDropdown.Items.FindByValue("Please select").Selected == false);
Debug.WriteLine(CustomerDropdown.Items.FindByValue("Please select").Selected == true);
return;
}

如何将下拉菜单设置回"Please select"运行ExportExcel(filename)方法后?我认为基本上我问的是我怎么设置后刷新CustomerDropdown选择"请选择">

customer下拉列表。

之后将选择第0个索引选择,即"Please select.">

你试过在你的代码中添加:

ExportExcel(filename);
// DataSet DropDownIndexSelection = (DataSet)ViewState["DropDownIndexSelection"];
CustomerDropdown.Items.Clear();
// CustomerDropdown.ClearSelection();
CustomerDropdown.DataTextField = dataSet.Tables[0].Columns["cust_id"].ToString();
CustomerDropdown.DataValueField = dataSet.Tables[0].Columns["cust_id"].ToString();
CustomerDropdown.DataSource = dataSet.Tables[0];  //assigning datasource to the dropdownlist  
// CustomerDropdown.Items[0].Selected = true;
CustomerDropdown.DataBind();  //binding dropdownlist 
CustomerDropdown.Items.Insert(0, new ListItem("Please select"));
CustomerDropdown.Items.Insert(1, new ListItem("All"));
CustomerDropdown.SelectedIndex=0; ---> Possible solution

?

来源:参考文献

相关内容

  • 没有找到相关文章

最新更新