从listview中为c#变量赋值 [英] assign to a c# variable a value from a listview

查看:175
本文介绍了从listview中为c#变量赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个列表视图(从数据库中检索数据)它有列(id,名称,价格,数量)



我想检查数量值,如果var <5则向管理员发送带有产品特征(ID,名称,价格)的电子邮件。



我发现以下代码可以发送电子邮件:

Hi guys,

I have a list view (which is retrieving data from a database) it has columns (id,name,price,quantity)

I want to check the quantity value and if it is var<5 to send an e-mail with products characteristics (id,name,price) to administrator.

I found the following code which works it sends email:

MailMessage mailObj = new MailMessage(
            "from", "to", "Product low quantity", "your product has low quantity");

        SmtpClient SMTPServer = new SmtpClient("localhost");
        try
        {
            SMTPServer.UseDefaultCredentials = false;
            SMTPServer.Host = "smtp.gmail.com";
            SMTPServer.Port = 587;
            SMTPServer.Credentials = new NetworkCredential("email", "password");
            SMTPServer.EnableSsl = true;
            SMTPServer.Send(mailObj);
        }
        catch (Exception ex)
        {
            // Label1.Text = ex.ToString();
        } 





所以我想以某种方式检查产品的数量



任何帮助?



提前致谢!!



Jason



so i want to check somehow the quantity of the product

Any help?

Thanks in advance!!

Jason

推荐答案

嘿那里,



试试这个:

首先添加 DataKeyNames ListView的属性,如: DataKeyNames = 数量

并使用此代码检查数量:

Hey there,

Try this:
Add DataKeyNames property of ListView first, like: DataKeyNames="quantity"
and Use this code to check quantity:
foreach (ListViewDataItem item in ListView1.Items)
            {
                int quantity = Convert.ToInt32(ListView1.DataKeys[item.DisplayIndex]["quantity"].ToString());
                if (quantity < 5)
                {
                    //Send Email here
                }
            }





您可以获得与Quanity相似的特定行的其他值。



希望它有帮助



Azee ......



You can get other values of a specific row similar to Quanity.

Hope it helps

Azee...


这篇关于从listview中为c#变量赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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