在添加产品的页中,可以不选定特定值,就时值为0,显示是"请选择",但是现在我要做修改页,需要读出原有的数据,那么默认值是数据库中已经存在的值,那样我该如何做?
下班是我采用的,请高手指导我如何修改
e,netscape,mozilla下通过
<!--#include file="conn.inc"-->
<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<title>两级关联菜单</title>
</HEAD>
<BODY>
<!--
by fason(2003.4.5)
表名:pro_city
结构:id(自编) province(文本) city(文本)
注释:conn.inc为连接数据库文件
ie,netscape,mozilla下测试通过
-->
<SCRIPT LANGUAGE=javascript>
<!--
var prv=new Array()//省
var cty=new Array()//市
function init(){
<%
dim prv,cty,i,j
i=0
set prv=conn.execute("select distinct province from pro_city")
if not prv.eof then
do while not prv.eof
j=0
%>
prv[<%=i%>]="<%=trim(prv("province"))%>";
<%
set cty=conn.execute("select city from pro_city where province='"&trim(prv("province"))&"'")
if not cty.eof then%>
cty[<%=i%>]=new Array()
<%do while not cty.eof%>
cty[<%=i%>][<%=j%>]="<%=trim(cty("city"))%>"
<%j=j+1
cty.movenext
loop
end if
cty.close :set cty=nothing
i=i+1
prv.movenext
loop
end if
prv.close :set prv=nothing
%>
if(prv.length >0){
for(i=0;i<prv.length;i++)
with(document.frm.province)options[length]=new Option(prv[i],prv[i])
document.frm.province.onchange=new Function("go(this.selectedIndex)")
}
}function go(sIndex){
with(document.frm.city){
length=0;
if(sIndex==0){options[0]=new Option("请选择");return}
for(i=0;i<cty[sIndex-1].length;i++)
options[length]=new Option(cty[sIndex-1][i],cty[sIndex-1][i])
}
}
window.onload=init
-->
</SCRIPT>
<form name=frm>
<SELECT name=province>
<OPTION selected>请选择</OPTION>
</SELECT>
<SELECT name=city>
<OPTION selected>请选择</OPTION>
</SELECT>
</form>
</BODY>
</HTML>

解决方案 »

  1.   

    你可以在服务器端做啊。<ItemTemplate>
    <INPUT class=btstyle onclick='javascript:OpenNewWindow(<%# DataBinder.Eval(Container.DataItem,"User_id")%>);' type=button value=修改>
    </ItemTemplate>
     private void Page_Load(object sender, System.EventArgs e)
    {
      ........
      GetInfo(GetInfo(Request["User_id"]););
      ........
    }
    private void GetInfo(string User_id)
    {  
    string strConn=ConfigurationSettings.AppSettings["SqlConn"];
    myConnection.ConnectionString=strConn;

    {
    string strCommand="select a.distinct,(select select city from pro_city  where User_id=a.User_id) as City  from pro_city a where User_id="+User_id ;
    SqlDataAdapter da=new SqlDataAdapter(strCommand,myConnection);
    DataSet ds=new DataSet();
    da.Fill(ds,"providers");
    if(ds.Tables["Providers"].Rows.Count>0)
    {
    frm.Text=ds.Tables["citys"].Rows[0]["City_id"].ToString();
    ........
    }