在ASP.NET中的现有数据视图中追加一行 [英] Append a row in existing dataview in ASP.NET
本文介绍了在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 theStringBuilder
class before thewhile
loop. Combine multiple filters withOR
. Assign theRowFilter
and return the result after thewhile
loop.
You should also be able to use aforeach
loop, rather than working directly with theIEnumerator
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屋!
查看全文