Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > binding ArrayLists to DataGrids-- how to name the columns?

Reply
Thread Tools

binding ArrayLists to DataGrids-- how to name the columns?

 
 
Jim Bancroft
Guest
Posts: n/a
 
      04-29-2005
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?


 
Reply With Quote
 
 
 
 
Sambathraj
Guest
Posts: n/a
 
      05-02-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>
>



 
Reply With Quote
 
 
 
 
Jim Bancroft
Guest
Posts: n/a
 
      05-02-2005
Thanks-- I'll give it a shot.

-Jim


 
Reply With Quote
 
Bob Weiner
Guest
Posts: n/a
 
      05-02-2005
I have the same problem. I want bind a DataGrid to a string array which
seems like it should be a simple thing to do.


I have
<Columns>
<asp:BoundColumn> HeaderText = "File Name"</asp:BoundColumn>
<asp:ButtonColumn> Text = "View" HeaderText = "View"</asp:ButtonColumn>
<asp:ButtonColumn> Text = "Download" HeaderText =
"Download"</asp:ButtonColumn>
</Columns>

In the code I have:
<snip>
dg.DataSource = outQueue.FileList; // string []
dbDataBind();
</snip>


With AutoGenerateColumns = "false", the DataGrid is empty. If I set
AutoGenerateColumns = "true" I get a 4th column labled "Item" which contains
my FileList. How do I get my FileList inside my first column? It would
seem it is an easy thing to do.




"Jim Bancroft" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
dynamically name dynamic arraylists drdave@canoemail.com ASP .Net 5 12-08-2005 06:47 PM
Comparing two arraylists =?Utf-8?B?RE9UTkVUR1VZ?= ASP .Net 1 08-24-2005 10:17 AM
binding ArrayLists to DataGrids-- how to name the columns? Jim Bancroft ASP .Net 3 05-02-2005 08:54 PM
ArrayList of ArrayLists: How to implement IEnumerable =?Utf-8?B?UG9udGlNYXg=?= ASP .Net 0 07-05-2004 02:12 PM



Advertisments