How to Cancel DataBind when using LINQDataSource Control?
At times, we will require cancelling the databind of LINQData source control. The below little code snippet will help us to do that.
ASPX <asp:GridView ID="GridView2" runat="server" DataSourceID="LinqDataSource2"> </asp:GridView> <asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="DataClassesDataContext" TableName="Employees" GroupBy="new(Location,Dept.Department)" Select="new (key.Location as City,key.Department as Department, Max(Age) as MaxAge)" onselecting="LinqDataSource2_Selecting"> </asp:LinqDataSource>
CodeBehind protected void LinqDataSource2_Selecting(object sender, LinqDataSourceSelectEventArgs e) { e.Cancel = true; }
Happy Coding!!
|