ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved. Replace null value with another value in Linq using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="nauna"> nauna</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;EmployeeId&#34; HeaderText=&#34;EmployeeId&#34; /&gt; &lt;asp:BoundField DataField=&#34;FirstName&#34; HeaderText=&#34;FirstName&#34; /&gt; &lt;asp:BoundField DataField=&#34;LastName&#34; HeaderText=&#34;LastName&#34; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using NorthwindModel;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports NorthwindModel</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { NorthwindEntities entity = new NorthwindEntities(); var query = (from o in entity.Orders join emp in entity.Employees on o.EmployeeID equals emp.EmployeeID into rd from rt in rd.DefaultIfEmpty() select new { EmployeeID = o != null ? (o.EmployeeID ?? 0) : 0, FirstName = rt.FirstName, LastName = rt.LastName }).Take(5); GridView1.DataSource = query; GridView1.DataBind(); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim entity As NorthwindEntities = New NorthwindEntities() Dim query = (From o In entity.Orders Group Join emp In entity.Employees On o.EmployeeID Equals emp.EmployeeID Into rd = Group From rt In rd.DefaultIfEmpty() Select New With {Key .EmployeeID = If(o IsNot Nothing, (If(o.EmployeeID, 0)), 0), Key .FirstName = rt.FirstName, Key .LastName = rt.LastName}).Take(5) GridView1.DataSource = query GridView1.DataBind() End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="" alt="" width="257" height="338" /></p>, 06 Jun 2019 02:18:11 GMT