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

[Solved] Checking for Empty Grid Items

4 Answers 530 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 28 Mar 2008, 12:15 PM
In my _ItemDataBound method, I am checking to see if a BoundColumn item is an empty/null string (i.e. the database field was empty).

I have this:

protected void systemsConfigGrid_ItemDataBound( object sender, GridItemEventArgs e ) 
    { 
       if(e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = e.Item as GridDataItem; 
 
            string authSerialNumber = dataItem["serialNumber"].Text; 
 
            if(String.IsNullOrEmpty(authSerialNumber)) 
             { 
                //Do something 
            } 
          } 
      } 
 

However, this piece of code never goes inside of the if check, even though I'm staring right at the serialNumbers column and it definitely has some empty fields.

Any help with this would be appreciated.

Thanks,
Stephen

4 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 28 Mar 2008, 03:00 PM
Hi Stephen,

You can also check the .Text property (dataItem["serialNumber"].Text)  and compare it with "". This would be another way to check for no text.

Kind regards,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Stephen
Top achievements
Rank 1
answered on 28 Mar 2008, 03:10 PM
Trust me, I tried that.  I don't know why this simple thing isn't working.
0
Vlad
Telerik team
answered on 28 Mar 2008, 03:14 PM
Hi Stephen,

Can you please check if there is a " " in the cell Text - the grid will add this automatically if the cell is empty. To avoid such problems you can use your DataItem directly. Here is an example for DataRowView:

        if(e.Item is GridDataItem)
        {
           DataRowView rowView = (DataRowView)e.Item.DataItem;
 
            if(rowView["serialNumber"] == DBNull.Value)
             {
                //Do something
            }
          }

All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Stephen
Top achievements
Rank 1
answered on 28 Mar 2008, 03:23 PM
That did it, Vlad.  Thanks a bunch, that was driving me absolutely crazy.



Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Stephen
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or