Fill Dropdown From Array

  • Thread starter Thread starter LacOniC
  • Start date Start date
L

LacOniC

Hi. I'm new to C# especially to arrays. I need a 3 dimension array to
fill a dropdown list in a web page.

TypeOfTest | MinPoint | Value

I'll use Type of Test and Value in dropdown. MinPoint will be shown in a
label near dropdown.

Can u help me?
 
Array is like that: (2 dimension, i said 3 in first message sorry)

string[,] TestType = { {"SAT1", "1", "1000"},

{"ACT", "2", "21"},

{"GCE 2 Certificates", "3", "2 Course"},

{"IB International Baccalaureate", "4", ""},

{"French Baccalaureate", "5", ""},
 
for (int r = 0; r < TestType.GetLength(0); r++)

ddlTypeOfTest.Items.Add(new ListItem(TestType[r,0], TestType[r,1]));

ddlTypeOfTest.DataBind();

-----------------------------------

private void ddlTypeOfTest_SelectedIndexChanged(object sender,
System.EventArgs e)

{

txtMinimumScore.Text = TestType[ddlTypeOfTest.SelectedIndex, 2];

}
 
LacOniC said:
Array is like that: (2 dimension, i said 3 in first message sorry)

string[,] TestType = { {"SAT1", "1", "1000"},

{"ACT", "2", "21"},

{"GCE 2 Certificates", "3", "2 Course"},

{"IB International Baccalaureate", "4", ""},

{"French Baccalaureate", "5", ""},

Actually, what you need is a 1-dimension array of objects:

class TestType
{
public string TypeOfTest;
public string MinPoint;
public string Value;
public TestType (string tt, string mp, string v)
{
TypeOfTest = tt;
MinPoint = mp;
Value = v;
}
public override string ToString()
{
return String.Format("{0} | {1} | {2}", TypeOfTest,
MinPoint, Value);
}
}


TestType [] TestTypes = new TestType[] {
new TestType("SAT1", "1", "1000"),
new TestType("ACT", "2", "21"),
new TestType("GCE 2 Certificates", "3", "2 Course"),
new TestType("IB International Baccalaureate", "4",
""),
new TestType("French Baccalaureate", "5", "")
}

foreach (TestType tt in TestTypes)
ddlTypeOfTest.Items.Add(tt);
ddlTypeOfTest.DataBind();

private void ddlTypeOfTest_SelectedIndexChanged(object sender,
System.EventArgs e)
{
TestType tt = ddlTypeOfTest.SelectedItem as TestType;
txtMinimumScore.Text = tt.Value;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top