Specializations

Tuesday, November 13, 2012

Linq with Grid view in ASP.net and C#.net

We have a grid view and it contains check boxes we want selected grid view information using Linq
 
1) Gridview checkbox seleted row values getting and updated list<> values
(from GridViewRow msgRow in gvSalesOrder.Rows
             where ((CheckBox)msgRow.FindControl("chkPONO")).Checked
             select ((Label)(msgRow.FindControl("ltlPNO"))).Text).ToList().ForEach(delegate(string p)
            {
                liEXPSOPO.Where(x => x.POID == p).ToList().ForEach(delegate(EXPSOPO di)
                {
                    if (di.STATUS == "N")
                        liEXPSOPO.Remove(di);
                    else di.STATUS = "R";
                });

            });
 FindControl("your controlname"):--This method is use full to get the control with in the grid row or with in the group controls. here we are using to get the infor mation with in the grid row.

(or)
another way to getting results

Using Lambda expressions to get the gridview selected row information with generic methods list
2)  Getting Grid view seleted valuesusing link
var checkedIDs = from GridViewRow msgRow in gvSalesOrder.Rows
                        where ((CheckBox)msgRow.FindControl("chkPONO")).Checked
                          select ((Label)(msgRow.FindControl("ltlPNO"))).Text;
//convert  checkedIDs  to list
string[] poids = checkedIDs.ToArray();

//list view content updation
liEXPSOPO.Where(x => x.POID == p).ToList().ForEach(delegate(EXPSOPO di)
               {
                 if (di.STATUS == "N")
                       liEXPSOPO.Remove(di);
                  else di.STATUS = "R";
              });

No comments:

Post a Comment