我正面臨一個問題。我在我的應用程序中設置了一些枚舉。像將字符串轉換爲Enum而不知道它是C類型的#
public enum EnmSection
{
Section1,
Section2,
Section3
}
public enum Section1
{
TestA,
TestB
}
public enum Section2
{
Test1,
Test2
}
EnmSection
是主枚舉,它包含另一個在它下面聲明的枚舉(作爲字符串)。現在我必須在下拉菜單中填寫EnmSection
的值。我已經完成了。 就像這個...
drpSectionType.DataSource = Enum.GetNames(typeof(EnmSection));
drpSectionType.DataBind();
現在我的下拉有值:Section1,Section2,Section3
問題是:
我還有一個下拉drpSubSection
。現在我想填充這個下拉列表,無論我在drpSectionType
中選擇了什麼。
對於ex如果我選擇了drpSectionType中的Section1,那麼drpSubsection應該包含值 TestA,TestB
。像這樣:
protected void drpSectionType_SelectedIndexChanged(object sender, EventArgs e)
{
string strType = drpSectionType.SelectedValue;
drpSubsection.DataSource = Enum.GetNames(typeof());
drpSubsection.DataBind();
}
這裏typeof()
期待enum.But我得到選定的值作爲字符串。我怎樣才能實現這個功能。
感謝
不工作。它給我錯誤: - 值不能爲空。 參數名稱:enumType – VSoni
這意味着Type.GetType沒有找到類型。你確定你有正確的枚舉名稱空間嗎? –
是的:)。你能爲我提供任何工作解決方案嗎? – VSoni