Visual Studio ASPX列表框 [英] Visual Studio ASPX ListBox

查看:150
本文介绍了Visual Studio ASPX列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在用aspx构建网页,到目前为止,我可以在列表框中显示我的SQL数据库中的某些值,但是现在我希望能够从该列表框中选择一个项目,并显示同一数据库中的另一个项目. >
最好的问候
谢谢.

Hello,

Im building a web page in aspx and so far i can show some values from my SQL database in a listbox, but now i want to be able to select an item from that listbox and show a diferent item from the same database.

Best Regard
Thank You.

推荐答案

您的意思是说您想要某种层叠列表框功能?
即您已将SQL服务器中的一些部门显示在列表框中
现在您要根据在列表框"中进行的选择

也就是说,假设已从列表框中选择帐户"部门,而您想从sql数据库中获取该部门的数据.

启用列表框的Autopostback属性,并在该Autopostback处理程序中进行类似于exisitng的数据库调用.

试试这样的东西:

You mean to say you want some sort of cascade List boxfunctionality?
i.e. you have shown some DEPARTMENTs from your SQL server into a List Box
and now you want that based on what selection has been made in List Box

i.e. let''s say "Accounts" department has been selected rom list box and you want to fetch data from sql database for that department.

Enable Autopostback property of the list box and make a database call similar to exisitng one in that Autopostback handler.

Try something like this :

<asp:listbox id="ListBoxA" runat="server" AutoPostBack="True"

OnSelectedIndexChanged="ListBoxA_SelectedIndexChanged"></asp:listbox>



和代码隐藏:



and codebehind :

protected void ListBoxA_SelectedIndexChanged(object sender, EventArgs e)
{
     // fetch data from sql server now
}


可以从该列表框中选择一个项目,并显示同一数据库中的另一个项目
那么,这是什么问题呢?

在执行服务器代码的任何触发事件中,找到列表框的选定项.如果要使用它从数据库中获取其他项目,请获取它.以您喜欢的方式显示新数据.

您可以使用按钮控件的click事件来回发页面,甚至可以在选择了列表框中的项目后甚至使用Listbox AutoPostback属性来回发页面.如果要替换所选项目,则需要用新项目设置值.如果只想使用它,请使用SelectedValue/SelectedItem获取并选择当前使用的项目.
able to select an item from that listbox and show a diferent item from the same database
So, what is the issue?

In any of your trigger event when server code is executed, find the selected item of listbox. If you want to use it to get other item from DB, get it. Show the new data the way you like.

You can use button control click event to postback your page or even use Listbox AutoPostback property to postback the page once you have selected item in our listbox. If you want to replace the selected item than you need to set the value with new one. If you just want to use it, then use SelectedValue/SelectedItem to get the current selected item and use it.


这篇关于Visual Studio ASPX列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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