Binding array index to control

  • Thread starter Thread starter Jason Chan
  • Start date Start date
J

Jason Chan

let say i have an array A of string

A[0] = "a";
A[1] = "b";
..... A[n] = "xyz"

to bind the value of array to control, i can use
<%# DataBinder.Eval(Container, "DataItem") %>

but how about if i want to bind the index of the array to control?

thanks in advance
 
Jason Chan said:
let say i have an array A of string

A[0] = "a";
A[1] = "b";
.... A[n] = "xyz"

to bind the value of array to control, i can use
<%# DataBinder.Eval(Container, "DataItem") %>

but how about if i want to bind the index of the array to control?

thanks in advance

A way can be this:
protected System.Web.UI.WebControls.DropDownList ddlArray;

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

{

if(!IsPostBack)

{

String[] strings = {"A", "B", "C"};

for(int i = 0; i < strings.Length; i++)

{

ListItem item = new ListItem(strings, i.ToString());

this.ddlArray.Items.Add(item);

}

}

}

HTH
 

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