私は、次のDropDownListコントロールを持っている:コードのドロップダウンリストを設定するには?
<asp:DropDownList ID="commission" class="form-control" runat="server">
<asp:ListItem Enabled="true" Text="Select Commission" Value="-1"></asp:ListItem>
<asp:ListItem Text="10%" Value="0.1"></asp:ListItem>
<asp:ListItem Text="15%" Value="0.15"></asp:ListItem>
<asp:ListItem Text="20%" Value="0.20"></asp:ListItem>
<asp:ListItem Text="25%" Value="0.25"></asp:ListItem>
</asp:DropDownList>
私は、データベースからドロップダウンリストの値を読んでいます。私は、オブジェクトのインスタンスに設定されていないオブジェクト参照を取得エラー。 これは私がしようとしているものです:
double com = reader.GetDouble(6);
if (com == 0.1)
{
commission.Items.FindByText("10").Selected = true; // I get the exeption here
}
else if (com == 0.15)
{
commission.Items.FindByText("15").Selected = true;
}
else if (com == 0.2)
{
commission.Items.FindByText("20").Selected = true;
}
else if (com == 0.25)
{
commission.Items.FindByText("25").Selected = true;
}
例外が発生していることについて質問するときは、例外がどこで発生しているのかを明示する必要があります。 – GEEF
FindByText(string)に%がありません –
[NullReferenceExceptionとは何ですか?それを修正する方法は?](http://stackoverflow.com/questions/4660142/what-is-a-ヌルリファレンスの抜け方ややり方はどうすればいいですか?) –