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. 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.
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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?
...
|
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";
|
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...
|
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,...
|
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...
|
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,...
|
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: 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...
|
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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |