473,465 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Change Datagrid Cell Value on Load

I'm trying to change a value of a cell based on another before the grid is
displayed. I'm using the ItemDataBound event like this for a simple test:

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
If e.Item.Cells(7).Text = String.Empty Then
e.Item.Cells(7).Text = "hello"
End If
End Select

The problem? e.Item.Cells(7).Text always shows that the cell is empty for
every row in the datagrid, even though some of the records being pulled from
the database might have a value for that cell!

To prove it, if I comment out the above Select/Case statements, the data
pulled from the database into the grid is displayed as it should be.

If it helps, the cell is a template column. Am I using the wrong event? I
tried to ItemCreated event before trying the ItemDataBound event, but that
didn't work either.
Nov 19 '05 #1
3 2420
Each cell has controls that are all part of the cell and render its
contents. You need to set the appropriate one.

Look at the HTML being rendered via View Source, and see what it looks like.

"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
I'm trying to change a value of a cell based on another before the grid is
displayed. I'm using the ItemDataBound event like this for a simple test:

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
If e.Item.Cells(7).Text = String.Empty Then
e.Item.Cells(7).Text = "hello"
End If
End Select

The problem? e.Item.Cells(7).Text always shows that the cell is empty for
every row in the datagrid, even though some of the records being pulled
from
the database might have a value for that cell!

To prove it, if I comment out the above Select/Case statements, the data
pulled from the database into the grid is displayed as it should be.

If it helps, the cell is a template column. Am I using the wrong event? I
tried to ItemCreated event before trying the ItemDataBound event, but that
didn't work either.

Nov 19 '05 #2
Hi Richard,

If the cell is a template column then the value you are looking for would be
in one of the controls within the cell (i.e. look for
e.Item.Cells(7).Controls(0).Text).

Your code would be clearer if you were to give that control within the
template column an ID then would be able to find it quickly using the
e.Item.FindControl("MyControlID") and cast it the appropriate control type.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Richard" wrote:
I'm trying to change a value of a cell based on another before the grid is
displayed. I'm using the ItemDataBound event like this for a simple test:

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
If e.Item.Cells(7).Text = String.Empty Then
e.Item.Cells(7).Text = "hello"
End If
End Select

The problem? e.Item.Cells(7).Text always shows that the cell is empty for
every row in the datagrid, even though some of the records being pulled from
the database might have a value for that cell!

To prove it, if I comment out the above Select/Case statements, the data
pulled from the database into the grid is displayed as it should be.

If it helps, the cell is a template column. Am I using the wrong event? I
tried to ItemCreated event before trying the ItemDataBound event, but that
didn't work either.

Nov 19 '05 #3
Thanks Phillip. Using FindControl worked!

"Phillip Williams" wrote:
Hi Richard,

If the cell is a template column then the value you are looking for would be
in one of the controls within the cell (i.e. look for
e.Item.Cells(7).Controls(0).Text).

Your code would be clearer if you were to give that control within the
template column an ID then would be able to find it quickly using the
e.Item.FindControl("MyControlID") and cast it the appropriate control type.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Richard" wrote:
I'm trying to change a value of a cell based on another before the grid is
displayed. I'm using the ItemDataBound event like this for a simple test:

Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
If e.Item.Cells(7).Text = String.Empty Then
e.Item.Cells(7).Text = "hello"
End If
End Select

The problem? e.Item.Cells(7).Text always shows that the cell is empty for
every row in the datagrid, even though some of the records being pulled from
the database might have a value for that cell!

To prove it, if I comment out the above Select/Case statements, the data
pulled from the database into the grid is displayed as it should be.

If it helps, the cell is a template column. Am I using the wrong event? I
tried to ItemCreated event before trying the ItemDataBound event, but that
didn't work either.

Nov 19 '05 #4

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

Similar topics

3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
1
by: strout | last post by:
I know it's dumb ... sometimes frustrating I want the text and a dropdownlist align with both side of a table cell, i.e. text align left and dropdownlist align right. I cannot add more cells to...
4
by: Roger | last post by:
I have a datagrid and would like to know what even fires when a cell is changed? I want to know when the user changes a cell and moves to the next. I have some code that needs to be done to...
5
by: Earl | last post by:
I want to fire a database update off of a single change to a single cell in the datagrid. This apparently cannot be done using keypress, keyup, keydown, etc. I've read George Shepard's FAQ and...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
2
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? ...
1
by: Tarik Monem | last post by:
Hi everyone and I hope that you can help. I am trying to send a value of a cell within a Datagrid to my php file which has a simple sql query: here's the php: <? $server = "localhost";
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...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.