Filtering the Data based on LINQ queries

  Linq Queries  

Take 3x1 table Write available categories

Drag & drop DropDownList

Drag & drop Grid View Control & set width Autoformat

Drag & drop LINQDataSource & set width Autoformat

Select LINQDataSource task & configure Database

Category Id

Category Name

For DropDown List: Choose DataSource: LINQDataSource

Untitled Category Name

For dropdown list: ddl available

AutoPostball: true

Double click on the Dropdown list

NorthWind DBDataContext dc = new NorthWindDBDataContext ();

Int cid = int.Parse (ddlCategories.SelectedItem.Value;

Var products = from product in dc.Products

Where

Product.Category Id = cid

Select new

?

Product.Product Id,

Product.ProductName,

Product = QuantityPerUnit,

Product.UnitPrice

};

GridView1.DataSource = Products;

GridView1.DataBind ();

Click on GridView tasks Untitled Edit columns à Uncheck auto-generate fields

Select BoundField

Click Add

Header Text: Product ID

DataFile ID: Product ID

Select HyperLink Field

Add                HeaderText: ProductName

DataNavigateURI Fields: Product ID

DataNavigateURIFormatString: Showorders by Id.aspx ? pid = {0}

DataTextField: Product Name

Select Bound field

Add                Header Text: Quanity

DataField: Quanity per unit

Unit Price

Website (menu) – Add New Webform

Name: ShowOrdersby Id  Untitled  take 3x1 table

  Linq Datasources  

Select LINQ Data Source tab Untitled Table: Order_details

Inclined to build a profession as VB.Net Developer? Then here is the blog post on, explore VB.Net Training

Select:

Linq Queries

Linq Queries

 

Select Grid View tasks:

ChooseDataSource: LINQDataSource

Click on edit columns

Command Field Untitled select Untitled add

Button Type: buttonUntitledSelect Text: Show Customer

OK  

Observation:

The data from Grid View can be read from 3 different event handles.

  • From the event handlers of external controls
  • From the selected Index changed event of Grid View (select [Command Field])

  • From any events of Grid View other  than selected Index changed

 

To refer to the Grid View row from selected Index changed event of Grid View:

Grid View name.Selected Row

To refer the Grid View Row from the events of Grid View other than Selected Index Changed;

e.Row (where “e” is a Grid View Row Event Args variable)  

Note:

Data within the Grid View Row will exist within the table cell of Grid View Row or within some control present within the table cell of Grid View Row.  

To read the Data from the Table cell of Grid View Row:

(Table cell) Grid View Row. Cells [cell index]

To read the value from the control present within the Table cell of GridViewRow

(Control Type) GridViewRow. Cells [cellindex]. Controls [Control index]

(Or)

(Control Type) GridViewRow. Cells [cellindex]. Find Control [Control Name]

Untitled If we check 101 and list delete it must be deleted (Check Box)

Gvl.Rows[0].Cells [0].Find Control (chkOrderId)  

// Double click on GridView

NorthWindDBDataContext dc = new NorthWindDBDataContext ();

Table oid = (Tablecell) GridView1.SelectedRow.Cells [0];

Int OrderId = int Parse (oid.Text)

Var cinfo = from customer in

dc.Orders where customer.OrderID = = OrderID

Select new

{

Customer.Customer.CompanyName,

Customer.Customer.ContextName,

Customer.Customer.CustomerID,

Customer.Customer.Country

} ;

GridView2.DataSource = cinfo;

GridView2.DataBind ();

Untitled Execute  

For an in-depth knowledge, click on below