简体   繁体   English

如何禁用上一页中选择的当前表单中的下拉列表值

[英]How to disable dropdown list value in the current form that was selected in the previous page

I am having 2 web formsand will have a drop down list on those web forms. 我有2个Web表单,这些Web表单上会有一个下拉列表。 If i select a value from drop down and click on ok i will get tranfer to next page. 如果我从下拉列表中选择一个值,然后单击确定,我将转到下一页。 In that page i will have a drop down with the same values in the previous form . 在该页面中,我将使用与先前表单中相同的值进行下拉。 What i need is i would like to disable the selected value in the previos form and would like to display the remaining normal 我需要的是我想禁用previos形式的选定值,并希望显示剩余的法线

I dont know your exact scenario but i would suggest that you look at whether you can maybe achieve your needs using a single form instead of two. 我不知道您的确切情况,但我建议您研究是否可以使用一种而不是两种形式来满足您的需求。

If that is not an option :- 如果那不是一个选择:

  1. If you are POSTING the form on click of OK, you can retrieve the value of the original page using PreviousPage. 如果单击“确定”来发布表单,则可以使用PreviousPage检索原始页面的值。 Refer eg below. 请参阅下面的示例。

I am not quite sure what you mean by "disable the selected value in the previos form and would like to display the remaining normal" but once you retrieve this value, then you can manipulate the data in your current page any way you want. 我不太确定“禁用previos形式的选定值并想显示剩余的法线”是什么意思,但是一旦检索到该值,就可以以任意方式操纵当前页面中的数据。

DropDownList oldValue = (DropDownList)PreviousPage.FindControl("DropDownOldValue");

oldValue.SelectedValue - should then give you the value selected on the previous page

Got the answer 得到了答案

    DropDownList oldvalue = (DropDownList)PreviousPage.FindControl("DropDownList1");
    string str = oldvalue.SelectedValue.ToString();

    ListItem i = DropDownList1.Items.FindByValue(str);
    i.Attributes.Add("style", "color:gray;");
    i.Attributes.Add("disabled", "true");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM