Tuesday, July 5, 2011

How to implement The NOT IN clause in LINQ?

First way:
var query =
from c in dc.Customers
where dc.Orders.FirstOrDefault(o=>o.CustomerID == c.CustomerID) ==  null
select c;

Second way:

var query =
from c in dc.Customers
where !(from o in dc.Orders
select o.CustomerID)
select c;

How to hide a column in Gridview?

If set visible to false in Gridview template, this column will not be rendered into html.  
<asp:BoundField DataField="ID" HeaderStyle-Width="0px" Visible="false" />

 Should add onrowdatabound event handler to do that:
<asp:GridView ID="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound">

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.RowType != DataControlRowType.DataRow) return;
    e.Row.Cells[1].Visible = false;

ModelBinder Conventions in ASP.NET MVC