-1

I have the following linq to sql query that i am binding to a detailsview

            var ShippingChallan = (from sc in db.ShippingChallanViewSeconds
                               where sc.challan_id == Convert.ToDecimal(txtChallanNo.Text) && sc.SecondWeight != null && sc.Type == "LBO"
                               select new { 
                                   sc.challan_id,
                                   sc.bowzer_no,
                                   sc.FirstWeight,
                                   sc.SecondWeight,
                                   sc.netWeight,
                                   sc.Product_Name,
                                   sc.FLD,
                                   sc.Customer_Name,
                                   sc.dip1,
                                   sc.Cmpt_Capacity1,
                                   sc.dip2,
                                   sc.Cmpt_Capacity2,
                                   sc.dip3,
                                   sc.Cmpt_Capacity3,
                                   sc.dip4,
                                   sc.Cmpt_Capacity4,
                                   sc.dip5,
                                   sc.Cmpt_Capacity5
                               }).FirstOrDefault();

In 99% rows, sc.dip4 and sc.dip5 are null.

I do not want to show the user these properties if they are null.

How do i do it??? any idea???

Shezi
  • 1,352
  • 4
  • 27
  • 51
  • I would have thought it was up to the detailsview to hide the nulls rather than the linq query to not return them... – Chris Jun 01 '12 at 10:21
  • In the detailsView you can tell it not to autogenerate fields and then explicitly add the fields you want. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.fields.aspx talks about the fields property and http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.autogeneraterows.aspx for the autogeneration. – Chris Jun 01 '12 at 10:59
  • Chris, the autogenerateRows property is false. what i am doing here is execute that linq Query and whatever result comes up, i bind it to the detailsview. dv1.DataSource = new[] { ShippingChallan }; dv1.DataBind(). A SIMPLE OPERATION. I want to check during any event like "DataBound" Event for any null value, and if found, set its visible property to false. And i can't get it to work. – Shezi Jun 01 '12 at 11:07
  • ok i got it myself and offcourse with your guidance: Here is what i came up with DV_ChallanDetails.AutoGenerateRows = false; BoundField bow = new BoundField(); bow.DataField = "bowzer_no"; bow.HeaderText = "Bowzer No"; DV_ChallanDetails.Fields.Add(bow); I DO IT FOR EVERY FIELD, AND IF ANY FIELD IS EMPTY AND JUST DON'T DISPLAY IT.. tHANKS – Shezi Jun 01 '12 at 11:29

1 Answers1

-1

ok i got it myself : Here is what i came up with

DV_ChallanDetails.AutoGenerateRows = false; 
BoundField bow = new BoundField();
bow.DataField = "bowzer_no"; 
bow.HeaderText = "Bowzer No"; 
DV_ChallanDetails.Fields.Add(bow); 

I DO IT FOR EVERY FIELD, AND IF ANY FIELD IS EMPTY AND JUST set its visible property to false

THANKS

Shezi
  • 1,352
  • 4
  • 27
  • 51