0
DropDownList
을 사용자가 작성하는 List
으로 채우려고합니다. 사용자는 공 이름과 그 무게를 입력하고 목록 상자에 추가됩니다. 기본 페이지에서 내가 가진 : 목록으로 DropDownList 채우기
List<Ball> myBall;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
myBall = new List<Ball>();
Session["listSession"] = myBall;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
Ball f = new Ball(TbxName.Text, int.Parse(TbxWeight.Text));
myBall= (List<Ball>)Session["listSession"];
myBall.Add(f);
foreach (var item in myBall)
{
ListBox1.Items.Add(item.getBallInfo());
}
내 볼 클래스에서
:public Ball(string n, int w)
{
name = n;
weight = w;
}
public string getBallInfo()
{
string s;
if (weight > 5)
{
s = name + " is huge"
}
else
{
s = name + " is small"
}
하는 방법은 DropDownList
와 다른 클래스에서 기본 클래스에서 볼 이름을 채울 수 있습니까?
감사 당신은 환영합니다 :)있어 – user2158735
답변 – Luaan