从静态数据设置下拉列表 [英] Set dropdownlist from static data

查看:77
本文介绍了从静态数据设置下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉框对象:


< asp:DropDownList ID =" ddlQuestionType" runat =" server">

< asp:ListItem Value =" MS" Text =Multiple Single />

< asp:ListItem Value =" MM" Text =Multiple Multiple />

< asp:ListItem Value =" TF"文本= QUOT;真/假" />

< / asp:DropDownList>


值和文本是静态的。我正在阅读一张桌子:


从myTable中选择QuestionType,其中id = 10


,QuestionType将为MS, ; MM"或者TF。


如何将数据绑定到此对象?


使用Label,它将类似于:


< asp:label id ="问题" Text =''<%#DataBinder.Eval(Container.DataItem,

" QuestionUnique")%>''runat =" server" />


谢谢,


汤姆。

解决方案

< blockquote>从SQL表中数据绑定很简单,你应该可以在那里找到很多

的例子。


你需要了解更多关于这个数据库的信息你但是要查询。


1.)是MS SQL服务器还是其他类型?

2.)你是否必须登录服务器,或者它是否接受继承的

凭证?

3.)您是否拥有要连接的数据库名称?


" Chad Devine" <苏***** @ gmail.com>在消息中写道

news:11 ********************* @ z14g2000cwz.googlegro ups.com ...

从SQL表中数据绑定很简单,你应该能够找到很多
的例子。

你需要了解更多关于你正在查询的数据库的信息。

1.)它是MS SQL服务器还是其他类型?
2.)您是否必须登录服务器,还是接受继承的凭证?
3.)你有连接的数据库名称吗?




Actuall,没有。


我怎么样这里的数据不是问题。


我可以获得数据。它总是MM,MS或TF。我也

没有问题绑定到文本框,标签,数据网格等。


<%#DataBinder.Eval(Container.DataItem," QuestionUnique" ;)%>


我想在这里做同样类型的事情,我所选择的项目将根据返回的数据显示




不知何故,我需要做类似的事情:


questionType.SelectedItem.value =<%#DataBinder.Eval(Container.DataItem,

" QuestionType")%>


这样该值将在下拉框中正确显示。


谢谢,


Tom


哦,所以你想让下拉列表改变当前选择的项目

to在桌子上的那个?我过去曾尝试过这样做,但是没有运气,我只是在运用asp.net的技能,所以

希望其他人可以为您提供解决方案。


可能需要您使用自定义控件来实现您想要做的事情。


I have a dropdownbox object:

<asp:DropDownList ID="ddlQuestionType" runat="server">
<asp:ListItem Value="MS" Text="Multiple Single" />
<asp:ListItem Value="MM" Text="Multiple Multiple" />
<asp:ListItem Value="TF" Text="True/False" />
</asp:DropDownList>

The values and text are static. I am reading from a table:

Select QuestionType from myTable where id = 10

and QuestionType will either be "MS", "MM" or "TF".

How do I bind the data to this object?

With a Label it would be something like:

<asp:label id="Question" Text=''<%# DataBinder.Eval(Container.DataItem,
"QuestionUnique") %>'' runat="server" />

Thanks,

Tom.

解决方案

Databinding from a SQL table is easy, you should be able to find many
examples out there.

You need to know more about this database you are querying though.

1.) Is it a MS SQL server or is it another type?
2.) Do you have to login to the server, or does it accept inherited
credentials?
3.) Do you have the database name you are connecting to?


"Chad Devine" <su*****@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...

Databinding from a SQL table is easy, you should be able to find many
examples out there.

You need to know more about this database you are querying though.

1.) Is it a MS SQL server or is it another type?
2.) Do you have to login to the server, or does it accept inherited
credentials?
3.) Do you have the database name you are connecting to?



Actuall, no.

How I get the data is not the issue here.

I can get the data fine. It will always be either MM, MS or TF. I also
have no problem binding to a textbox, label, datagrid etc.

<%# DataBinder.Eval(Container.DataItem, "QuestionUnique") %>

I want to do the same type of thing here where my selected item will display
based on the data returned.

Somehow, I need to do something like:

questionType.SelectedItem.value = <%# DataBinder.Eval(Container.DataItem,
"QuestionType") %>

So that the value will show correctly in the dropdownbox.

Thanks,

Tom


Oh so you want the dropdownlist to change the currently selected item
to the one that''s in the table? I have tried doing that in the past but
haven''t had any luck, I''m only intermediate in skill with asp.net so
hopefully someone else can provide a solution for you.

It may require you to go as far as using a custom control for what you
are trying to do.


这篇关于从静态数据设置下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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