如何获取当前的ListBox1.SelectedItem.Text [英] How to get the current ListBox1.SelectedItem.Text
问题描述
在我的页面中,我有2个列表框,一个Fileupload控件和一个Display按钮。
我必须按照以下操作:
1.如果我在listBox1中选择一个值Get from DB,那么数据将从数据库表格并显示在gridview中。
- 这种情况正在发生。
2.如果我在listBox1中选择值upload,则应启用Fileupload控件。
- 这也正在发生。
3.当我在文件上传控件中上传excel文件并点击显示时,列表文件中的工作表名称列表应该显示在ListBox2中。
- 这也正在发生。
4.当我选择时列表框2中的任何工作表名称,应从工作簿的选定工作表名称中读取数据并显示为网格。
- 问题出在这一步,只要我选择它,它会自动选择Ind ex 0和索引0处工作表名称的数据将显示在网格视图中。
为了更清楚无论工作表名称如何,我选择索引处的工作表名称列表框中的0被视为。
请帮助。
谢谢和问候,
Mathi。
Hi,
In my page I have a 2 list boxes, a Fileupload control and a Display button.
I have to follow the below actions:
1. If I select a value "Get from DB" in listBox1 then the data will be fetched from DB Table and shown in a gridview.
-- This is happening.
2. If I select a value "upload" in listBox1 then the Fileupload control should be enabled.
-- This is also happening.
3. When I upload an excel file in the file upload control and click on display, The list of sheet names in the excel file should be displayed in ListBox2.
-- This is also happening.
4. When I select any sheet name in the list box 2, the data should be read from the selected sheet name of the workbook and get displayed as grid.
-- The issue is in this step only, whatever sheet I select it is automatically selecting the Index 0 and the data from the sheet name at index 0 is getting displayed in the grid view.
To be more clear whatever sheet name I select the sheet name at Index 0 of the list box is considered.
Please help.
Thanks & Regards,
Mathi.
推荐答案
检查一下。它应该工作 -
Check this. It should work-
string text_value = listBox2.GetItemText(listBox2.SelectedItem);
如果这不起作用,请告诉我:))
If this is not working, please let me know :)
我找到了解决方案。
我正在使用ListBox2.SelectedItem.Text来获取值。
但是在分配DataFieldValue时我默认情况下,所有列表项都给出了0。
因此,无论我选择它根据DataFieldValue考虑,因为索引0中的Item也将DataFieldVlaue设置为0,无论我默认选择哪个项目,它都是考虑索引0处的项目。
解决方案:仅将列表绑定为ListBox2.DataSource并且没有明确提及任何DataFieldValue。
全部谢谢。
问候,
Mathi。
I have found the solution.
I'm using ListBox2.SelectedItem.Text to fetch the value.
But while assigning the DataFieldValue I have given 0 by default for all the List Items.
So whatever I select it considers based on the DataFieldValue, since Item in Index 0 is also having the DataFieldVlaue as 0 whatever Item I select by default it is considering the Item at Index 0.
Solution: Just bound the list alone as ListBox2.DataSource and didnt mention explicitly abount any DataFieldValue.
Thanks all.
Regards,
Mathi.
这篇关于如何获取当前的ListBox1.SelectedItem.Text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!