如何将值从 var 添加到列表视图

本文关键字:添加 列表 视图 var | 更新日期: 2023-09-27 18:29:51

public static bool loadFileview(Int64 uname,out string[] filename,out string[] extn)
{
        bool b = false;
        SCPEntities ent = new SCPEntities();
        filename = null;
        extn = null;
        var data = (from n in ent.User_Data where n.Account_Num == uname select new { n.File_Name, n.Extn }).ToList();
        int i = 0;
        foreach (var v in data)
        {
            filename[i] = v.File_Name;
            extn[i] = v.Extn;
            i++;
        }
        if(liv1!=n)
        {
            b = true;
            // liv = data;
        }
        return b;
    }
}

方法调用

protected void Page_Load(object sender, EventArgs e)
{
        string[] fname;
        string[] extn;
        Int64 uname = 12121;
        bool b = false;
       b= home.loadFileview(uname, out fname,out extn);
       if (b)
       {
           for (int count = 0; count <fname.Length; count++)
           {
               ListViewItem listItem = new ListViewItem(fname[count]);
               listItem.SubItems.Add(extn[count]);
               FileListView.Items.Add(listItem);
           }
}

我想动态地将filenameextn绑定到 listview 控件 listview11,如何?

如何将值从 var 添加到列表视图

试试这个:

protected void Page_Load(object sender, EventArgs e)
{
    string[] fname;
    string[] extn;
    Int64 uname = 12121;
    bool b = false;
   b= home.loadFileview(uname, out fname,out extn);
   if (b)
   {
       for (int count = 0; count <fname.Length; count++)
       {
           ListViewItem listItem = new ListViewItem (new[] { fname[count], extn[count]})
           FileListView.Items.Add(listItem);
       }
   }
}