Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Datagrid Problem...

Status
Not open for further replies.

bartee

MIS
Mar 20, 2005
147
US
I have the following in the databound event for the datagrid:

e.Item.Cells(1).Text = e.Item.Cells(2).Text.Trim.Length

When there is text in cells(2), it correctly displays the length.

When there is no text, it always displays the lenth as 6.

I can't figure it out -- the lenght in the source data is 0 for rows that are blank.

Any thing I might not be seeing here?
 
This may have something to do with your DB. Is it a SQL server your pulling from? You may have to trim both cells.

 
your saying
e.Item.Cells(1).Text = e.Item.Cells(2).Text.Trim.Length

<<When there is text in cells(2), it correctly displays the length.

why are you worried about the length? is the text cutting off?? you need to provide a little more info then just saying "it correctly displays the length" Trimming the cells or textboxes, labels etc. trims it back to the last character of the control.

The reason I asked what DB your running is, what type are your fields? varchar, char, int what??

<<When there is no text, it always displays the lenth as 6.

what do you mean by that? your saying when the cursor hits that cell, there are six blank spaces behind were the cursor sits?

 
I will try and be more descriptive.

I have a dataset that is filled from SQL.

I created a DataView from that Dataset and in turn, created a DataGrid control using the DataView as the DataSet.

In the DataGrid, I have a few columns. One of the columns is based on the "CompanyName" field. This field is nvarchar character type.

I was trying to identify when the field was blank on the ItemDataBound event but it was not working correctly -- that is why I was displaying the lenght -- and hence, the code I provided earlier.

Problem is that when the CompanyName is blank, it displays the length as 6. When the companyname is not blank, say it's ABC Company, it displays the lenght correctly at 11.

The data coming from the database to fill the dataset has been trimmed and does not equal to 6 blank characters -- I checked.

This is where my confusion is.

Any suggestions are appreciated.

Thanks again.
 
as far as i am aware DataGrid outputs a HTML table, in HTML if a table must be shown as empty it must have &nbsp; (its length is 6) in it.


try this:
if e.Item.Cells(2).Text="&nbsp;" then
response.write("Empty!")
end if

Known is handfull, Unknown is worldfull
 
Add a watch on e.Item.Cells(2).Text.Trim() and what do you get for the value when it gives you 6 as the length?

 
your welcome...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top