asp中实现最简单的下拉菜单,

asp中实现最简单的下拉菜单,,第1张

<td width=118 align=right>婚姻状况:</td>

<td width=382>

<select name=marrage>

<option value=0 selected>未婚</option>

<option value=1 <% if marrage="1" then response.write "selected"%>>已婚</option></select>

</select>

这是最简单的

复杂一点的有

<td width=118 align=right>月收入:</td>

<td width=382>

<select name="earning">

<%

sql=" SELECT * FROM t_earning"

rs.open sql,conn,3,1

for i=1 to rs.recordcount

response.write "<option value="&rs("c_earning_id")

if rs("c_earning_id")=cint(earning) then response.write " selected "

response.write ">"&trim(rs("c_earning_txt"))&"</option>" &vbCrLf

rs.movenext

next

rs.close

%>

</select>

还是用个下拉框吧,单击文本框,你还得多做一个下拉框来调用,自己给自己找麻烦。

假设从表aaa中取字段bbb作为下拉列表:

打开记录的代码

<%

dim rs,strsql

set rs=server.CreateObject("adodb.recordset")

strsql="select distinct bbb from aaa" '选出不重复的bbb

rs.open strsql,conn,1,1

%>

-----------------------------------------------------------------------

下拉框的代码

<p>请选择:<select size="1" name="bbb" style="width: 150">

<option value=" "></option> '第一个选项为空白

<%while not rs.Eof%>

<option value=<%=rs("bbb")%>><%=rs("bbb")%></option>

<%

rs.movenext

wend

%>

</select></p>

1. 设置属性 IsEditable="True" Combobox就可编辑

2. 下拉框正常绑定数据就行,如果像上图每个Item都有个删除功能,那就需要重写样式,可参考下面的代码(带有动画效果,可删除)

<Style TargetType="{x:Type ComboBoxItem}">

<Setter Property="SnapsToDevicePixels"

Value="true"/>

<Setter

Property="HorizontalContentAlignment" Value="Stretch"/>

<Setter

Property="VerticalContentAlignment" Value="Center"/>

<Setter Property="Padding"

Value="3"/>

<Setter Property="Focusable"

Value="False"/>

<Setter Property="Template">

<Setter.Value>

<ControlTemplate

TargetType="{x:Type ComboBoxItem}">

<Grid SnapsToDevicePixels="true" FocusVisualStyle="{x:Null}">

<Rectangle x:Name="BackgroundHighlight" FocusVisualStyle="{x:Null}"

Margin="-1" Stroke="#A0FFFFFF"/>

<ContentPresenter

Content="{Binding LoginName}" FocusVisualStyle="{x:Null}"

HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"

VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"

x:Name="contentPresenter" Margin="{TemplateBinding Padding}"/>

<Button Width="30"

Height="30" HorizontalAlignment="Right" Tag="{Binding LoginName}"

Style="{StaticResource CloseButton}" Click="BtnDeleteRecord_Click"/>

</Grid>

<ControlTemplate.Triggers>

<Trigger

Property="IsMouseOver" Value="True">

<Trigger.ExitActions>

<BeginStoryboard

Storyboard="{StaticResource HoverOff}"

x:Name="HoverOff_BeginStoryboard"/>

</Trigger.ExitActions>

<Trigger.EnterActions>

<BeginStoryboard

Storyboard="{StaticResource HoverOn}"

x:Name="HoverOn_BeginStoryboard"/>

</Trigger.EnterActions>

</Trigger>

<Trigger

Property="IsHighlighted" Value="true"/>

<Trigger

Property="Selector.IsSelected" Value="True">

<Trigger.ExitActions>

<BeginStoryboard

Storyboard="{StaticResource SelectedOff}"

x:Name="SelectedOff_BeginStoryboard1"/>

</Trigger.ExitActions>

<Trigger.EnterActions>

<BeginStoryboard

Storyboard="{StaticResource SelectedOn}"

x:Name="SelectedOn_BeginStoryboard1"/>

</Trigger.EnterActions>

</Trigger>

</ControlTemplate.Triggers>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/8000987.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存