CheckBoxListから青と赤のような2色を、4つのオプションのパラメータと最終的な合成結果を出力するメソッドに送信します。CheckBoxList項目をメソッドに送信する方法は?
これはCheckBoxListのである:
Choose Two Colors:
<asp:CheckBoxList ID="CheckBoxList1" runat="server" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Yellow</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
</asp:CheckBoxList>
これは、4つのオプションのパラメータを取得するメソッドです:誰かがCheckBoxListのから2つの色を選択したときに
static string ColorMixer(string Blue = "NotDefined", string Yellow = "NotDefined", string Red = "NotDefined",
string Green = "NotDefined")
{
string blue = Blue;
string yellow = Yellow;
string red = Red;
string green = Green;
string results;
if (blue.Equals("Blue")&&yellow.Equals("Yellow"))
{
results = "GREEN";
return results;
}
if (red.Equals("Red")& green.Equals("Green"))
{
results = "Brown";
return results;
}
the rest of codes goes here ....
else
{
results = "Result is Unspecified";
}
return results;
}
は今、私のようなコードを持つ2つの色を取得したいですこれは:
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
string selectedoptions;
selectedoptions = item.Text;
}
}
}
そして、選択された文字列アイテムを名前parameメソッドに合わせる
文字列 "selectedoptions"から選択した色をどのように取得し、それをどのようにフォーマットできますか?
ColorMix(Blue:"Blue",Red:"Red")
ここで、「青」と「赤」はユーザーが選択した色です。
あなたの問題やエラーを適切に特定してください! – Null
誰かがチェックボックスリストから2つの色を選択したければ、名前付きパラメータとしてアイテムをメソッドに送信できます。 – Mohsen