我们如何从ListView中选择一行并在文本框中显示其数据? [英] How can we pick a Row from ListView and Display its Data in Text Box?

查看:337
本文介绍了我们如何从ListView中选择一行并在文本框中显示其数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用Grid View,我们可以从Grid View中选择一行,并使用以下方式在TextBox中显示其数据.

txtDishName.Text =((标签)(grdDishDetails.SelectedRow.FindControl("lblDishName")))).Text;

但是我们如何才能从ListView中选择一行并在文本框中显示其数据呢?

请告诉我.....

By Using Grid View We Can Pick a row from Grid View and Show its data in TextBox using the following way.

txtDishName.Text = ((Label)(grdDishDetails.SelectedRow.FindControl("lblDishName"))).Text;

But how can we pick a row from ListView and Show its Data in the Text Box???

please tell me.....

推荐答案

解决方案是您可以在ListView控件的selection change事件中获取它.Sender对象实际上是当前选中的对象ListView,您可以将行作为对象,如下所示

The solution is you can get it in the selection changed event of the ListView control.. Sender object is actually the current selected ListView you could get the row as object like below

var res = (sender as ListView).SelectedItem;




无论您用于填充列表视图如何,都可能必须将selectedItem强制转换为当前对象




You may have to cast the selectedItem to your current object whatever you have used to fill the list view

var res = (classname)(sender as ListView).SelectedItem;


这篇关于我们如何从ListView中选择一行并在文本框中显示其数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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