This is a migrated thread and some comments may be shown as answers.

Cell value set to "" return  

3 Answers 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Filleau
Top achievements
Rank 1
Filleau asked on 16 Sep 2008, 01:23 PM
Hi

I have a little problem with empty cells.
If I set a cell to ""  the cell return &nbsp
I understand this.

I would like to know if there is a way that cell.text return nothing.

Actualy I have to put a lot of if in order to have the good result.

For

Each item As GridDataItem In Grille.Items 
  
If item.Selected Then 
    
If item("Tel.").Text <> "&nbsp;" Then ZTel.Text = item("Tel.").Text Else ZTel.Text = "" 
    If item("Nom").Text <> "&nbsp;" Then ZNom.Text = item("Nom").Text Else ZNom.Text = "" 
    
If item("Soc").Text <> "&nbsp;" Then ZSoc.Text = item("Soc").Text Else ZSoc.Text = "" 
    
If item("Lieu").Text <> "&nbsp;" Then Zlocal.Text = item("Lieu").Text Else Zlocal.Text = "" 
    
If item("Prenom").Text <> "&nbsp;" Then ZPrenom.Text = item("Prenom").Text Else ZPrenom.Text = "" 
    
If item("Gsm").Text <> "&nbsp;" Then Zgsm.Text = item("Gsm").Text Else Zgsm.Text = "" 
    If item("Servic").Text <> "&nbsp;" Then Zservice.Text = item("Servic").Text Else Zservice.Text = "" 
    
If item("email").Text <> "&nbsp;" Then Zemail.Text = item("email").Text Else Zemail.Text = "" 
    
If item("titre").Text <> "&nbsp;" Then Ztitre.Text = item("titre").Text Else Ztitre.Text = "" 
    
If item("Sam").Text <> "&nbsp;" Then ZSamSec.Text = item("Sam").Text Else ZSamSec.Text = "" 
    
If item("Sec").Text <> "&nbsp;" Then Zsec.Text = item("Sec").Text Else Zsec.Text = "" 
    
If item("Telsec").Text <> "&nbsp;" Then Zsectel.Text = item("Telsec").Text Else Zsectel.Text = "" 
    Exit For
  End If
Next


Is there a best way ???

Thanks all

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Sep 2008, 04:23 PM
Hello Filleau,

I suppose this approach may give you some ideas:

C#:
foreach (GridDataItem item in RadGrid1.MasterTableView.GetSelectedItems()) 
    foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        (FindControl("Z" + col.UniqueName) as TextBox).Text = (item[col.UniqueName].Text != "&nbsp;") ? item[col.UniqueName].Text : null
 

VB:
 For Each item As GridDataItem In RadGrid1.MasterTableView.GetSelectedItems() 
     For Each col As GridColumn In RadGrid1.MasterTableView.RenderColumns 
         TryCast(FindControl("Z" + col.UniqueName), TextBox).Text = IIf((item(col.UniqueName).Text <> "&nbsp;"),item(col.UniqueName).Text,Nothing
     Next 
 Next 

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Filleau
Top achievements
Rank 1
answered on 17 Sep 2008, 07:54 AM
Thanks Daniel

Your approach is very good, but I'm affraid it will more optimize the number of line code than the application speed.

What I'm looking for is to improve performance.

So what il would like to do will be to delete all the tests (if) but I don't want to see "nbsp," in my text box  if my cell grid is équal to Nothing.
0
Daniel
Telerik team
answered on 22 Sep 2008, 08:48 AM
Hello Filleau,

You can choose either approach depending on your scenario. Other solution would be to use ItemDataBound event, but you will also have to check for nbsp content.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Filleau
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Filleau
Top achievements
Rank 1
Share this question
or