如何为返回的 ListOf 行创建自动生成 id
我正在访问数据列表,如下所示。
var result = (from Pages in PagesList.Items.OfType<SPListItem>()
select new ListImages
{
desc = Convert.ToString(Pages["Description"])
}).ToList();
我想要的是为生成的行数自动生成自定义增量 id。 例如,slide-img-1、slide-img-2 等。
public class ListImages
{
string _desc;
string _id;
public string id
{
get
{
if (_id != null)
return _id;
else
return string.Empty;
}
set { _id = value; }
}
public string desc
{
get
{
if (_desc != null)
return _desc;
else
return string.Empty;
}
set { _desc = value; }
}
}
谢谢,
Ashish
I am accessing list of data as shown below.
var result = (from Pages in PagesList.Items.OfType<SPListItem>()
select new ListImages
{
desc = Convert.ToString(Pages["Description"])
}).ToList();
What I want is to auto generate customized increamental id for the no of rows generated.
ex, slide-img-1, slide-img-2 etc.
public class ListImages
{
string _desc;
string _id;
public string id
{
get
{
if (_id != null)
return _id;
else
return string.Empty;
}
set { _id = value; }
}
public string desc
{
get
{
if (_desc != null)
return _desc;
else
return string.Empty;
}
set { _desc = value; }
}
}
Thanks,
Ashish
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道是否可以使用 Linq 特定语法来实现,但是像这样编写查询,您可以使用 .Select() 提供索引的方法:
I don't know if it can be achieved with the Linq specific syntax, but writing your query like this, you could use the .Select() method that provides an index: