473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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?
Nov 19 '05 #1
3 1555
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?

Nov 19 '05 #2
Thanks-- I'll give it a shot.

-Jim
Nov 19 '05 #3
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" <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?

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: TPSreport | last post by:
ASP.NET 2003. Two DataGrids, six columns each, one grid atop the other. I need to have the columns line up, i.e., DataGrid1 Col(1) lined up w/ DataGrid2 Col(1) - each the same width on the...
0
by: Carlos | last post by:
I’m constructing a Windows Forms application that accesses SQLServer data via a dataset. The dataset contains 2 tables “tblMaster” and “tblDetail” which are related in a one-to-many relationship...
0
by: Carl Smith | last post by:
I’m constructing a Windows Forms application that accesses SQLServer data via a dataset. The dataset contains 2 tables “tblMaster” and “tblDetail” which are related in a one-to-many relationship on...
1
by: Julia | last post by:
Hi I have a class Document which contains ArrayList of properties I want to bind the document to a datagrid,in such a way that I would be able to control which properties are being...
7
by: erniej | last post by:
as per instructions in the walkthrough, I have managed to create a master/detail relationship between two datagrids. However I have a requirement to apply this to three datagrids and the third...
2
by: iKiLL | last post by:
Hi All, My background is that i am new to C- Sharp and OOP. I have been working with it for about 2 Weeks. I do have good experionce in developing in things like VB6, COM, ASP, JavaScript and i...
0
by: Brandon Driesen | last post by:
The following illustrates my question. Why is it when I bind to an a collection of items whose interface implementation is explicit, there is an error during the binding process wherein the error...
6
by: UtLinh | last post by:
I have a table with a lot of columns (and I don't know exactly names of these columns). How can I add data (data is calculated via function) for these columns using only index_col?
1
by: hbkiwi | last post by:
Hi, Just playing with Access fairly new to it (like days old). Also it's my first post here so if I'm in the wrong place, sorry.. What I'm wanting to know is basically I have lets call it Table...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.