473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ 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.It em, ListItemType.Al ternatingItem
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 2435
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*****@discus sions.microsoft .com> wrote in message
news:9A******** *************** ***********@mic rosoft.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.It em, ListItemType.Al ternatingItem
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).Te xt).

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.FindCont rol("MyControlI D") 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.It em, ListItemType.Al ternatingItem
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).Te xt).

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.FindCont rol("MyControlI D") 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.It em, ListItemType.Al ternatingItem
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
3017
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 download a fully working C# sample with the Northwind.mdb here: www.insightgis.com.au/web/stuff/DataGridCombo.zip
2
3171
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp, Selecting Rows by Clicking Anywhere). Private Sub DataGrid1_ItemDataBound(ByVal...
1
2079
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 do format because it's in a Datagrid pager area. The html code generated for pager is one sigle cell with lots of colspan. I tried to add some...
4
10691
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 make sure entry is valid? Thanks, Rog
5
1580
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 while I may have overlooked it, I have not found an answer. I now am using the CurrentCellChanged event, and this is satisfactory IF the user moves off...
2
2838
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 appears in the cell, but allways the first item in the dropdown box is shown not the current cell value? How do I make the current value in the cell ...
3
2111
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 TableCell; DataGridItem item = cell.Parent as DataGridItem; int index = item.ItemIndex;
2
2247
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? "Curtis" <curtsfakeguy@hotmail.com> wrote in message
1
2016
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";
0
7446
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7809
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.