这个怎么判断呀,特别是这种项很多的时候
解决方案 »
- 这里的方括号是什么意思啊?
- 客户端暂存数据的问题
- 怎样将存入SESSION 中的值取出来呢?
- asp.net页面缓存和生成静态页面综合考虑哪个好?如果是静态页面,那有什么比较好的实施方法?
- 如何得到用户上传到服务器上的Flash文件的长度和宽度?
- ASP.NET用母版页,怎么让不同页面使用不同的CSS文件.
- System.DateTime currentTime=new System.DateTime(); 怎样在页面上输出currentTime的值?
- 如何用javascript与数据库数据间的操作 asp.net
- 初级问题(数据库连接)
- 各位大哥~请问asp与asp.net兼容问题~~~~救急
- 提交表单时,下拉菜单项如果没有就可以在textbox里填写提交!
- 反射框架效率高吗?
这个挺好的
不过这里猜LZ的js不是很熟,建议用DropDownList的AutoPostBack属性设为true,然后在DropDownList的选中事件中判断,如果选中“其他”这个项的值,就把textbox的visible的值设为true就可以显示了
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("select").change(function() {
if ($(this).val() == "-1") {
if ($("#txt_" + $(this).attr("id")).length > 0) {
$("#txt_" + $(this).attr("id")).show();
}
else {
$(this).after("<input type='text' id='txt_" + $(this).attr("id") + "' name ='txt_" + $(this).attr("id") + "'/>");
}
}
else {
if ($("#txt_" + $(this).attr("id")).length > 0) {
$("#txt_" + $(this).attr("id")).hide();
}
}
}); $("#btnSave").click(function() {
var flag = true;
$(":selected[value='-1']").each(function() {
if ($.trim($(this).parent().next().val()) == "") {
flag = false;
return false;
}
});
return flag;
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
DropDownList1:<asp:DropDownList runat="server" ID="DropDownList1">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试2" Value="2"></asp:ListItem>
<asp:ListItem Text="测试3" Value="3"></asp:ListItem>
<asp:ListItem Text="测试4" Value="4"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList2:<asp:DropDownList runat="server" ID="DropDownList2">
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList3:<asp:DropDownList runat="server" ID="DropDownList3">
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList4:<asp:DropDownList runat="server" ID="DropDownList4">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试2" Value="2"></asp:ListItem>
<asp:ListItem Text="测试3" Value="3"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList5:<asp:DropDownList runat="server" ID="DropDownList5">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList6:<asp:DropDownList runat="server" ID="DropDownList6">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试2" Value="2"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList7:<asp:DropDownList runat="server" ID="DropDownList7">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList8:<asp:DropDownList runat="server" ID="DropDownList8">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试2" Value="2"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList9:<asp:DropDownList runat="server" ID="DropDownList9">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试2" Value="2"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList10:<asp:DropDownList runat="server" ID="DropDownList10">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList11:<asp:DropDownList runat="server" ID="DropDownList11">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList12:<asp:DropDownList runat="server" ID="DropDownList12">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试2" Value="2"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList13:<asp:DropDownList runat="server" ID="DropDownList13">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试2" Value="2"></asp:ListItem>
<asp:ListItem Text="测试3" Value="3"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList14:<asp:DropDownList runat="server" ID="DropDownList14">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试2" Value="2"></asp:ListItem>
<asp:ListItem Text="测试3" Value="3"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList15:<asp:DropDownList runat="server" ID="DropDownList15">
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList16:<asp:DropDownList runat="server" ID="DropDownList16">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList17:<asp:DropDownList runat="server" ID="DropDownList17">
<asp:ListItem Text="测试1" Value="1"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList18:<asp:DropDownList runat="server" ID="DropDownList18">
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList19:<asp:DropDownList runat="server" ID="DropDownList19">
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
DropDownList20:<asp:DropDownList runat="server" ID="DropDownList20">
<asp:ListItem Text="测试5" Value="5"></asp:ListItem>
<asp:ListItem Text="测试6" Value="6"></asp:ListItem>
<asp:ListItem Text="测试7" Value="7"></asp:ListItem>
<asp:ListItem Text="其他" Value="-1"></asp:ListItem>
</asp:DropDownList><br />
<asp:Button runat="server" ID="btnSave" Text="提交" onclick="btnSave_Click" />
</div>
</form>
</body>
</html>
protected void btnSave_Click(object sender, EventArgs e)
{
Response.Write("DropDownList1:"+(DropDownList1.SelectedValue=="-1"?Request.Form["txt_"+DropDownList1.ClientID]:DropDownList1.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList2:" + (DropDownList2.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList2.ClientID] : DropDownList2.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList3:" + (DropDownList3.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList3.ClientID] : DropDownList3.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList4:" + (DropDownList4.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList4.ClientID] : DropDownList4.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList5:" + (DropDownList5.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList5.ClientID] : DropDownList5.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList6:" + (DropDownList6.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList6.ClientID] : DropDownList6.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList7:" + (DropDownList7.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList7.ClientID] : DropDownList7.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList8:" + (DropDownList8.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList8.ClientID] : DropDownList8.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList9:" + (DropDownList9.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList9.ClientID] : DropDownList9.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList10:" + (DropDownList10.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList10.ClientID] : DropDownList10.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList11:" + (DropDownList11.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList11.ClientID] : DropDownList11.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList12:" + (DropDownList12.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList12.ClientID] : DropDownList12.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList13:" + (DropDownList13.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList13.ClientID] : DropDownList13.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList14:" + (DropDownList14.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList14.ClientID] : DropDownList14.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList15:" + (DropDownList15.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList15.ClientID] : DropDownList15.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList16:" + (DropDownList16.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList16.ClientID] : DropDownList16.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList17:" + (DropDownList17.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList17.ClientID] : DropDownList17.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList18:" + (DropDownList18.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList18.ClientID] : DropDownList18.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList19:" + (DropDownList19.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList19.ClientID] : DropDownList19.SelectedValue));
Response.Write("<br/>");
Response.Write("DropDownList20:" + (DropDownList20.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList20.ClientID] : DropDownList20.SelectedValue));
}
我怎么样才能当drodownlist里没值时就调用textbox的值呢?
JS我知道呢,我是想知道如果要往数据库里传值,怎么样不选下拉菜单的值的话就自动传TEXTBOX的值到数据库呢!
统一调用textbox的值,当drodownlist的值发生变化时,用它的值更新textbox里的值
在提交数据库时,判断textbox是否为空,不为空就提交。
大概:if(dropdownlist.SelectedValue="无")
{
this.textbox.Visible = true;
……
}
else
{
……
}
if (!string.IsNullOrEmpty(textbox))
{
提交……
}
else
{
……
}