473,387 Members | 1,545 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,387 software developers and data experts.

access table cell by name not by index?

I have a dynamic datagrid in which the number of columns of not fixed, the
number of columns is selected from a dropdown.

I have one column header called "Brand/Model" and on the onItemDataBound i
want to modify the values relates to this column.. the problem is because the
index value is not fixed i can't use .. e.Item.Cells[int].Text

My question is how can i reference the cell by the cloumn header "BrandModel"?
is there a another way this solve this?

many thanks in advance..
Jul 21 '05 #1
7 1807
Huzz,

Never access a datagrid using the grid itself, access it by using the
datasource of it.

I hope this helps?

Cor
Jul 21 '05 #2
Cor thanks for your reply..
I don't know how to access it by datasource.. can you show me what code i
need to write.. or any good article?

many thanks
"Cor Ligthert" wrote:
Huzz,

Never access a datagrid using the grid itself, access it by using the
datasource of it.

I hope this helps?

Cor

Jul 21 '05 #3
Huzz,

I made this sample the day before yesterday however the OP did not give any
reaction on this.
However maybe it is now helpfull for you.

The only thing you have to do for it is drag a datagrid and a button on a
form paste this code bellow in, set the events in the code and run.

private void button1_Click(object sender, System.EventArgs e)
{
DataView dv = (DataView)this.dataGrid1.DataSource;
DataTable dt = dv.Table;
DataRow dr = dt.NewRow();
dr.ItemArray = new object[] {2,"002","Thee - Ceylon"};
dt.Rows.Add(dr);
int i = 0;

if ((string)dv.Sort == "[ItemId]") {i = dv.Find("002");}
else if (dv.Sort == "[Quantity]") {i = dv.Find(2);}
else if (dv.Sort == "[ItemName]") {i = dv.Find("Thee - Ceylon");}
this.dataGrid1.Select(i);
}
private void FormLoad(object sender, System.EventArgs e)

{
DataTable dt = new DataTable();
dt.Columns.Add("Quantity");
dt.Columns.Add("ItemID");
dt.Columns.Add("ItemName");

for (int i = 0; i < 3; i++) {
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);}

dt.Rows[0].ItemArray = new object[] {3,"001","Coffee - Black"};
dt.Rows[1].ItemArray = new object[] {1,"015", "Donut - Boston Creme"};
dt.Rows[2].ItemArray = new object[] {1,"005","Donut - Plain"};
DataView dv = new DataView(dt);
this.dataGrid1.DataSource = dv;
}

}

I hope this helps?

Cor
Jul 21 '05 #4
Since you know the name of the column you could iterate through the
column names and grab the index of the desired column. Here's an
example that just spits out the column names and their index.:
private void dg1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = (ListItemType)e.Item.ItemType;
if(itemType == ListItemType.Header)
{
for(int i = 0; i < dg1.Columns.Count; i++)
{
Response.Write("Column Text = " + dg1.Columns[i].HeaderText.ToString()
+ " - Index = " + i.ToString() + "<br>");
}
}
}

Jul 21 '05 #5
Vince,

Yes and then? What do you want to tell me?

Cor
Jul 21 '05 #6
Sorry. I guess that I click the wrong "Reply" link. I just meant to
offer huzz another alternative.

Jul 21 '05 #7
Thanks everyone for your help.. i'll have a go at it tomorrow sometime..

"huzz" wrote:
I have a dynamic datagrid in which the number of columns of not fixed, the
number of columns is selected from a dropdown.

I have one column header called "Brand/Model" and on the onItemDataBound i
want to modify the values relates to this column.. the problem is because the
index value is not fixed i can't use .. e.Item.Cells[int].Text

My question is how can i reference the cell by the cloumn header "BrandModel"?
is there a another way this solve this?

many thanks in advance..

Jul 21 '05 #8

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

Similar topics

0
by: yurps | last post by:
Hello here is my html, if you click the missing image in the first column on the left, the div is shown, when clicked again the div disappears...but the bottom border disappears as well...Is there...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
41
by: Ruby Tuesday | last post by:
Hi, I was wondering if expert can give me some lite to convert my word table into access database. Note: within each cell of my word table(s), some has multi-line data in it. In addition, there...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
28
by: Giggle Girl | last post by:
Can someone show me how to insert a row at any given row index of an already created table? It only has to work in IE6 (used on intranet at work). Specifically, if a table is 20 rows in total...
4
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
2
by: TG | last post by:
Hi! I am trying to export only the visible columns from a datagridview in my windows form in VB 2008. Should't it be no comma after the first row where the headers are? Also should...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.