使用 ref 将 GridView 列传递给方法
因此,我正在从事从 VB 到 C# Web 应用程序的迁移,并遇到了一个问题,我希望有一个简单的解决方案。有一个使用 GridView 控件的 Web 窗体。在代码中,它将列集合传递到一个方法中,该方法根据用户、权限和环境动态添加列。因此,列在 VB 中使用 ByRef 传递到函数中,如下所示:
Public Sub PopulateColumns(ByRef ColumnCollection As DataControlFieldCollection)
'Do something
End Sub
现在在 C# 中,我使用了 ref 关键字,但列集合没有 setter。我对此最快的解决方法是什么?我很快就会将其转换为 jQuery 网格,因此我不关心最佳实践,而只是让它发挥作用。
这是 C# 中的:
public void PopulateColumns(ref DataControlFieldCollection columnCollection)
{
// Something here
}
它的调用方式如下...
.PopulateColumns(ref EmployeeGridView.Columns)
So I'm working on this VB to C# web application migration and came across an issue that I'm hoping there is an easy work around for. There's a webform that uses the GridView control. In code, it passes the columns collection into a method that adds columns dynamically based on the user, permissions, and environment. So, the columns were passed into the function in VB using ByRef like so:
Public Sub PopulateColumns(ByRef ColumnCollection As DataControlFieldCollection)
'Do something
End Sub
Now in C#, I've used the ref keyword, but the columns collection doesn't have a setter. What's my quickest workaround for this? I'm going to be converting this over to a jQuery grid soon so I'm not concerned with best practices, but rather just getting it to work.
Here it is in C#:
public void PopulateColumns(ref DataControlFieldCollection columnCollection)
{
// Something here
}
which is called like this...
.PopulateColumns(ref EmployeeGridView.Columns)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该集合已经是 ByRef,因此您不需要 ref 参数。
所以,
除非我有一个金发时刻,你只需要做:测试并工作。
The collection is already ByRef, so you do not need the ref argument.
So,
unless I'm having a blonde moment, you just have to do:Tested and working.