473,396 Members | 2,093 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,396 software developers and data experts.

One more problem with DataGrid

I am trying to iterate through a datagrid using the following code:

private void updateFCA(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
for (int i = 0; i < e.Item.Cells.Count - 1; i ++)
{
if (e.Item.Cells[3].Text == "FCA")
{
e.Item.Cells[3].Text = "FCA";
}
else if (e.Item.Cells[3].Text == "")
{
e.Item.Cells[3].Text = "N";
}
else
{
e.Item.Cells[3].Text = "Y";
}
}
}

Thie iteration does not work as the int i value is not used. How do I alter
the code to fix this problem?

Thanks,

Dave
Nov 16 '05 #1
4 1066
There is a space between the "i" and the "++" (i.e., "i ++" should be "i++")

"kscdavefl" wrote:
I am trying to iterate through a datagrid using the following code:

private void updateFCA(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
for (int i = 0; i < e.Item.Cells.Count - 1; i ++)
{
if (e.Item.Cells[3].Text == "FCA")
{
e.Item.Cells[3].Text = "FCA";
}
else if (e.Item.Cells[3].Text == "")
{
e.Item.Cells[3].Text = "N";
}
else
{
e.Item.Cells[3].Text = "Y";
}
}
}

Thie iteration does not work as the int i value is not used. How do I alter
the code to fix this problem?

Thanks,

Dave

Nov 16 '05 #2
I corrected that problem but the program still does not iterate through the
column.

Thanks,

"XPhaktor" wrote:
There is a space between the "i" and the "++" (i.e., "i ++" should be "i++")

"kscdavefl" wrote:
I am trying to iterate through a datagrid using the following code:

private void updateFCA(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
for (int i = 0; i < e.Item.Cells.Count - 1; i ++)
{
if (e.Item.Cells[3].Text == "FCA")
{
e.Item.Cells[3].Text = "FCA";
}
else if (e.Item.Cells[3].Text == "")
{
e.Item.Cells[3].Text = "N";
}
else
{
e.Item.Cells[3].Text = "Y";
}
}
}

Thie iteration does not work as the int i value is not used. How do I alter
the code to fix this problem?

Thanks,

Dave

Nov 16 '05 #3
"kscdavefl" <ks*******@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Thie iteration does not work as the int i value is not used. How do I alter the code to fix this problem?


Why are using the for loop in the first place when all you apparently want
to do is manipulate cell #3?
Nov 16 '05 #4
You have several problems with your concept here:

i<e.Item.Cells.Count-1 would mean, if your loop did anything at all, that
you would never process the last cell. You should use i<e.Item.Cells.Count.
If you have 4 cells, you will iterate cells 0, 1, 2, 3. With the way you
have it, you would iterate cells 0, 1, 2.

Secondly, you don't ever reference i within your loop so why a for loop? It
is not clear how you are determining that i is not used. Your code should
loop through the columns, and therefore use i at least as the loop counter,
with the exception that I outlined in the first paragraph above: you will
never execute a count on the last column.

You call for Cells[3] in every iteration of your loop so you do exactly the
same thing each iteration. When your loop completes, Cells[3] is always
going to be FCA or Y since your last else will replace all the N values with
Y on the second iteration.

Next, why iterate the columns at all? Unless your entire data structure is
dynamic, then FCA should be in the same cell position, apparently in
Cells[3].

Perhaps you really mean to iterate through the rows using e.Items?

Also, you may want to replace your long series of if else statements with a
switch statement.

HTH

DalePres
MCAD, MCDBA, MCSE
"kscdavefl" <ks*******@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
I am trying to iterate through a datagrid using the following code:

private void updateFCA(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
for (int i = 0; i < e.Item.Cells.Count - 1; i ++)
{
if (e.Item.Cells[3].Text == "FCA")
{
e.Item.Cells[3].Text = "FCA";
}
else if (e.Item.Cells[3].Text == "")
{
e.Item.Cells[3].Text = "N";
}
else
{
e.Item.Cells[3].Text = "Y";
}
}
}

Thie iteration does not work as the int i value is not used. How do I
alter
the code to fix this problem?

Thanks,

Dave

Nov 16 '05 #5

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

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
1
by: Joe Bloggs | last post by:
I am trying display the contents of a table in a web page, select certain rows from that table and then display the fields that I have selected (now table columns) as text in a Label object....
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
3
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
7
by: Neo Geshel | last post by:
Greetings. I have a serious problem. I have multiple sets of tables, several of which are chained more than two tables deep. That is, I have a parent, a child, and a great-grandchild table. ...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.