在ASP.NET中的现有数据视图中追加一行 [英] Append a row in existing dataview in ASP.NET

查看:91
本文介绍了在ASP.NET中的现有数据视图中追加一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击链接查看



I have a asp.net page with User picker control which can take more than one names and filter out on click of Filter button for those particular entered names in UserPicker but it is filtering out one by one using dataview in the below code , I have a written the code but while looping it is taking the last name and displaying the records.

In this case how to Append a row for the given existing dataview.





我是什么尝试过:





What I have tried:

IEnumerator users = UserPicker.ResolvedEntities.GetEnumerator();
              while (users.MoveNext())
              {
                  SPUser selectedUser = web.EnsureUser(((Microsoft.SharePoint.WebControls.PickerEntity)(users.Current)).Key);
                  string strVendorUserName = selectedUser.LoginName.ToString();

                  if (strVendorUserName != null || ddlPermissionType.SelectedItem != null)
                  {
                      StringBuilder sb = new StringBuilder(string.Format("UserLoginName = '{0}'", strVendorUserName.Trim()));

                      dv.RowFilter = sb.ToString();

                      return dv;


                  }

推荐答案

声明 StringBuilder 之前的类,而循环。将多个过滤器与 OR 组合在一起。分配 RowFilter 并在之后返回结果,同时循环。



您还应该能够使用 foreach 循环,而不是直接使用 IEnumerator 界面。

Declare the StringBuilder class before the while loop. Combine multiple filters with OR. Assign the RowFilter and return the result after the while loop.

You should also be able to use a foreach loop, rather than working directly with the IEnumerator interface.
var sb = new StringBuilder();

foreach (Microsoft.SharePoint.WebControls.PickerEntity item in UserPicker.ResolvedEntities)
{
    SPUser selectedUser = web.EnsureUser(item.Key);
    string strVendorUserName = selectedUser.LoginName;
    if (strVendorUserName != null || ddlPermissionType.SelectedItem != null)
    {
        if (sb.Length != 0) sb.Append(" OR ");
        sb.AppendFormat("UserLoginName = '{0}'", strVendorUserName.Trim()); // <-- Possible NullReferenceException here!
    }
}

dv.RowFilter = sb.ToString();
return dv;



注意:看着你的如果阻止,您认为 LoginName 可以返回 null 。但如果确实如此,并且 ddlPermissionType.SelectedItem <$ c> c> null ,那么 strVendorUserName.Trim()将失败,并带有 NullReferenceException


NB: Looking at your if block, you believe that LoginName could return null. But if it does, and ddlPermissionType.SelectedItem is not null, then strVendorUserName.Trim() will fail with a NullReferenceException.


这篇关于在ASP.NET中的现有数据视图中追加一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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