gpt4 book ai didi

c# - ASP .NET - 从选定的 Listview 控制行中检索值?

转载 作者:行者123 更新时间:2023-11-30 22:47:58 26 4
gpt4 key购买 nike

我的 Listview 控件包含 4 列和 30 行。我可以使用以下方法检索行号:

//get row of listview item
ListViewDataItem item1 = e.Item as ListViewDataItem;
int findMe = item1.DisplayIndex;

然后如何从一列或所有 4 列中获取值?

我在尝试:

this.lblReponseRoute.Text = item1.FindControl("routenameLabel").ID.ToString();

更新 1:

最终的解决方案是:

//get row of listview item
ListViewDataItem item1 = e.Item as ListViewDataItem;
int findMe = item1.DisplayIndex;

//find label value
var routeLabel = (Label)ListView1.Items[findMe].FindControl("routenameLabel");
this.lblReponseRoute.Text = routeLabel.Text;

最佳答案

如果 routenameLabel 是服务器控件,我相信您必须在访问属性之前将其强制转换为服务器控件:

var routeLabel = (Label)item1.FindControl("routenameLabel");
lblResponseRoute.Text = routeLabel.ID.ToString();

您发布的代码是否有错误?

编辑:请注意,在您的真实代码中,您需要在转换到标签之前测试是否为 null。

关于c# - ASP .NET - 从选定的 Listview 控制行中检索值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2029699/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com