Hi,
Try the following way. Instead of adding string into the arrylist add class
objects exposing required properties.
class Task
{
private string _TaskName;
private string _Editable;
private int _Priority;
public Task(string TaskName, string Editable, int Priority)
{
_TaskName = TaskName;
_Editable = Editable;
_Priority = Priority;
}
public string TaskName { get { return _TaskName; } }
public string Editable { get { return _Editable; } }
public int Priority { get { return _Priority; } }
}
/// <summary>
/// Summary description for WebForm2.
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
public ArrayList Arr1;
private void Page_Load(object sender, System.EventArgs e)
{
ArrayList arr = new ArrayList();
// Start initial creation and filling of array.
arr.Add (new Task ("Tomorrow's work", "yes", 2));
arr.Add (new Task ("Today's work", "yes", 1));
arr.Add (new Task ("Yesterday's work", "No", 3));
DropDownList1.DataSource = arr;
DropDownList1.DataTextField = "TaskName";
DropDownList1.DataValueField = "Priority";
DropDownList1.DataBind();
DropDownList1.Attributes.Add("onChange","Javascrip t: alert(this.value)") ;
}
}
Regards,
Sambathraj
"Jim Bancroft" <as******@nowhere.com> wrote in message
news:OT*************@TK2MSFTNGP10.phx.gbl...
Hi everyone,
I'm binding an ArrayList to a DataGrid for the first time (I'm used to
binding DataSets and DataTables) and I was wondering if I could somehow
"name" the ArrayList, so that I can refer to it as a DataField in an
asp:BoundColumn?
In essence, I'm doing this:
ArrayList Arr1 = new ArrayList();
Arr1.Add("John");
Arr1.Add("Melissa");
Arr1.Add("Tim");
MyDataGrid.DataSource = Arr1;
MyDataGrid.DataBind();
Now I'd like to use an <asp:BoundColumn> control in the DataGrid, but I
don't know what the DataField value is for the ArrayList I just added.
Can I somehow associate a DataField value with the ArrayList?