使用LINQ的ListView控件 [英] ListView Control with LINQ

查看:136
本文介绍了使用LINQ的ListView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们.
我有一个表tblCustomerDetails.在这里,我想根据CustID删除记录.
我的所有数据都显示在ListView中.现在,我希望使用Linq to SQL从列表以及数据库中删除选定的CustID.
我制作了一个客户"类,要为此编写删除功能.
请帮助我.
我将如何在函数中传递选定的ListView控件.
我的客户分类代码:

Hi frnds.
i''ve a table tblCustomerDetails.here i want to delete record on the basis of CustID.
All My data is showing in ListView.Now i wish to delete selected CustID from list as well as dataBase using Linq to SQL.
I made a class "Customer" where want to write delete function for this.
plz help me how can i do it.
how i''ll pass selected listview control in function.
my code of class Customer:

public void Deletecustomer(tblCustomerDetails1 CustID)
    {

        CustomerDataContext db = new CustomerDataContext();

        db.tblCustomerDetails1s.DeleteOnSubmit(CustID);
        db.SubmitChanges();
    }




完全可以通过单击按钮找到ListView控件,现在如何传递上述功能?

按钮代码:




Altough i found ListView control on button click,now how to pass in above function??

Button code:

protected void Button1_Click(object sender, EventArgs e)
   {
       foreach (ListViewItem itemRow in lvCustomer.Items )
       {
           //for (int i = 0; i < itemRow.SubItems.Count; i++)

           Label  CustID = ((Label)itemRow.FindControl("Cust_IDLabel"));
           int a = int.Parse (CustID.Text);

                  }
   }

推荐答案

您可以将custID作为int传递给deletecustomer函数,并删除具有custID的记录.
函数调用之后,可以在button1_click()中重新加载/刷新列表视图.

You can pass the custID as int to the deletecustomer function and delete the record having custID.
After the function call, you can reload/refresh the listview, in the button1_click().

public void Deletecustomer(int CustID)
    {

        CustomerDataContext db = new CustomerDataContext();
        Table<customerdetails> tblCustomerDetails = db.Gettable<customerdetails>();
        CustomerDetails selectedCustomer = (CustomerDetails)tblCustomerDetails.Select(c=>c.custID == CustID);
        db.tblCustomerDetails.DeleteOnSubmit(selectedCustomer);
        db.SubmitChanges();
    }



这对您有帮助吗?

问候
Swami



Does this help you?

Regards
Swami


Rewite Button1_Click按照以下方式....

Rewite Button1_Click following way....

protected void Button1_Click(object sender, EventArgs e)
   {
       CustomerDataContext db = new CustomerDataContext();
       
       foreach (ListViewItem itemRow in lvCustomer.Items )
       {

           Label  CustID = ((Label)itemRow.FindControl("Cust_IDLabel"));
           int a = int.Parse (CustID.Text);
	   db.tblCustomerDetails1s.DeleteAllOnSubmit(db.tblCustomerDetails1s.Where(c => c.CustID == a));

        }
	db.SubmitChanges();

   }


这篇关于使用LINQ的ListView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆