Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve variable from LINQ query
    text
    copied!<p>I am having problem when trying to retrieve something from LINQ query. I got a prodList which store all the product records. And another list is distSPUItemList which store the record distributed item records. Here is the codes:</p> <pre><code>//Get list of products based on category and bind data to grid view prodList = prodPackBLL.getAllProductByCategory(category); gv.DataSource = prodList; gv.DataBind(); //Mark checkbox checked for products included in standard packing list var SPUItemList = new List&lt;DistributionStandardPackingUnitItems&gt;(); SPUItemList = packBLL.getAllSPUItemByDistributionID(distributionID); //LINQ query to compare lists of objects finding ProductPacking //objects whose name property are equal to the items in SPUItemList var available = from a in prodList // perform an inner-join between prodList and SPUItemList only // (x =&gt; x.name == a.name) compares b.name to a.name, this is // specifically what enforces that names match from b in SPUItemList.Where(x =&gt; x.name == a.name) // after inner joining is done, only select objects from prodList select a; //Iterate the gridview rows GridView gvForCheckBox = (GridView)e.Item.FindControl("gvProduct") as GridView; foreach (GridViewRow gr in gvForCheckBox.Rows) { if (available.Where(x =&gt; x.name == gr.Cells[1].Text).Any()) { CheckBox cb = (CheckBox)gr.Cells[0].FindControl("cbCheckRow"); cb.Checked = true; TextBox tb = (TextBox)gr.Cells[3].FindControl("tbQuantity"); //From here retrieve name and pass it to data access layer to perform SQL //Display unitQuantity if name match. If not default text set to 0 } } </code></pre> <p>So basically what I am trying to do is <code>from if (available.Where(x =&gt; x.name == gr.Cells[1].Text).Any()){}</code>, if the name is match, I mark the checkBox checked.<br> At the same time, I need to get the <code>unitQuantity</code> to be packed based on the <code>productName</code> from database. But I have no idea how to retrieve the name out of the LINQ query.</p> <p>Sorry for my poor explanation and thanks in advance.</p> <p>Edited Portion:</p> <pre><code> string name = gr.Cells[1].Text; int productQuantity = packBLL.getProductQuantityByName(name); TextBox tb = (TextBox)gr.Cells[3].FindControl("tbQuantity"); tb.Text = productQuantity.ToString(); </code></pre> <p>It works with this. First, I get the name by specifying the column and then I perform some other Sql statement</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload