单击<asp:button后,将变量(例如数组)从一个<asp:ListItem>传递到另一个(cf.<asp:DropDownList>>

Pass variables (e.g. array) from one <asp:ListItem> to another one (cf.<asp:DropDownList>) after clicking on <asp:button>

提问人:dark.vador 提问时间:7/21/2020 更新时间:7/23/2020 访问量:42

问:

上午全部

我一直在想如何在单击后将变量从一个 (cf. ) 传递到另一个变量,因为数据由于 .为了说明我的观点:<asp:ListItem>asp:DropDownList<asp:Button OnClick>auto-refresh

在 Page.aspx 上

<asp:DropDownList ID="test" runat="server" style="font-size:14px;text-align:center;border-radius:0; 
CssClass="ddl">                              
<asp:ListItem>&nbsp;&nbsp;&nbsp;&nbsp;checkfruit</asp:ListItem>
<asp:ListItem>;&nbsp;&nbsp;&nbsp;&nbsp;verify</asp:ListItem>
<asp:ListItem>bsp;&nbsp;testcheck</asp:ListItem>                           
 </asp:DropDownList>
<asp:Button OnClick="test_Click" return="false" ID="veg" Text="Submit" runat="server" style="margin- 
 left:30px; border-radius:0; width:90px;/>

在代码隐藏 .cs 上

```public double[] pte = new double[3]; //

protected void test_Click(object sender, EventArgs e)
{

string a = test.SelectedItem.Value;

switch(a)
{

case "verify":
double[] d = new double[3];
d = [8,2,1];
pte = d; 
break;

case "testcheck":
double c;
c = pte[0] + 1;
break;
}
}

其目的包括在依次单击这些选项后传递 from to 的值,从而导致 in 。问题是,当一个人从 to 切换到固有的 时,会被重新初始化,并且从 的设置并没有改善这个问题。理想情况下,我希望通过在 中重新定义来避免重复代码。因此,您的反馈将不胜感激。pverifytestcheckc = 9testcheckp0verifytestcheckauto-refreshtest_Clickreturn="false"page.aspxdtestcheck

最好

C# asp.net 下拉列表 ASPBuject

评论


答:

1赞 GRFRM 7/22/2020 #1

要保留 PostBack 中 pte 中设置的值,请将其保存到 ViewState 中

protected void test_Click(object sender, EventArgs e)
{
    string a = test.SelectedItem.Value;

    switch (a)
    {

        case "verify":
            double[] d = new double[3] { 8, 2, 1 };
            //d = [8, 2, 1];
            pte = d;
            ViewState["pte"] = pte; // Save values
            break;

        case "testcheck":
            double c;
            pte = ViewState["pte"] as double[]; // Read values
            c = pte[0] + 1;
            break;
    }
}

评论

0赞 dark.vador 7/23/2020
非常感谢 ,因为我一直在探索其他涉及 , , .最好smart way aroundjavascriptajaxc#