DROPDOWNLIST中取值问题(急)
我在DROPDOWNLIST中动态链接了几个数值SubGetAR_CATEGORY()DimSQLAsStringDimdataSet1AsDataSetDimintIn...
我在DROPDOWNLIST中动态链接了几个数值
Sub GetAR_CATEGORY()
Dim SQL As String
Dim dataSet1 As DataSet
Dim intIndex As Integer
Me.dropdownlist1.Items.Clear()
Me.dropdownlist1.Items.Add("---请选择---")
Me.dropdownlist1.Items(0).Value = "-1"
SQL = "SELECT MEANING,LOOKUP_CODE FROM SYS_LOOKUP_VALUES WHERE APPLICATION_ID=40 AND LOOKUP_TYPE_NAME='ar category'"
dataSet1 = clsDB.GetDataSet(SQL)
For intIndex = 0 To dataSet1.Tables(0).Rows.Count - 1
Me.dropdownlist1.Items.Add(dataSet1.Tables(0).Rows(intIndex).Item(0).ToString)
Me.dropdownlist1.Items(intIndex + 1).Value = dataSet1.Tables(0).Rows(intIndex).Item(1).ToString
Next
If dataSet1.Tables(0).Rows.Count = 1 Then Me.dropdownlist1.SelectedIndex = 1
End If
dataSet1.Dispose()
End Sub
可是这样的话我在调用textbox1.Text = dropdownlist1.SelectedItem.Text时只能得到“--请选择--”
是哪里出了问题了吗?(数据库中得到的值是1、2、3)
我已经把数据库的值显示出来,现在就是把值显示到上面 展开
Sub GetAR_CATEGORY()
Dim SQL As String
Dim dataSet1 As DataSet
Dim intIndex As Integer
Me.dropdownlist1.Items.Clear()
Me.dropdownlist1.Items.Add("---请选择---")
Me.dropdownlist1.Items(0).Value = "-1"
SQL = "SELECT MEANING,LOOKUP_CODE FROM SYS_LOOKUP_VALUES WHERE APPLICATION_ID=40 AND LOOKUP_TYPE_NAME='ar category'"
dataSet1 = clsDB.GetDataSet(SQL)
For intIndex = 0 To dataSet1.Tables(0).Rows.Count - 1
Me.dropdownlist1.Items.Add(dataSet1.Tables(0).Rows(intIndex).Item(0).ToString)
Me.dropdownlist1.Items(intIndex + 1).Value = dataSet1.Tables(0).Rows(intIndex).Item(1).ToString
Next
If dataSet1.Tables(0).Rows.Count = 1 Then Me.dropdownlist1.SelectedIndex = 1
End If
dataSet1.Dispose()
End Sub
可是这样的话我在调用textbox1.Text = dropdownlist1.SelectedItem.Text时只能得到“--请选择--”
是哪里出了问题了吗?(数据库中得到的值是1、2、3)
我已经把数据库的值显示出来,现在就是把值显示到上面 展开
展开全部
关于这个,我用c#解决了两个问题:
1、下拉框是固定的值,修改时要将添加时选的值读出来并选中,比如用户注册时的省份
2、下拉框是动态读取的,修改时要选中添加时的选项,如修改产品时,类别是动态读取的,要选中添加产品的那个类别
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Server.MapPath(@"..\App_Data\Product.mdb"));
try
{ //根据传来的产品pid到产品表中表查询产品,并读出来
if (Request.QueryString["pid"] != null)
{
Session["pid2"] = Request.QueryString["pid"].ToString();
}
else
{
Response.Write("参数错误!");
Response.End();
}
//Session["pid2"] = Convert.ToString(Request.QueryString["pid"].Trim());
OleDbConnection conn = dbconn.createProductConnectionInAdmin();
conn.Open();
OleDbCommand cmdr = new OleDbCommand("select * from Product where pid='" + Convert.ToString(Session["pid2"])+"'", conn);
OleDbDataReader rs = cmdr.ExecuteReader();
if (rs.Read())
{
if (rs["pdiscount"].ToString() !="0")//折扣一般是固定的
{
this.pdiscount1.SelectedValue = rs["pdiscount"].ToString(); //固定值时下拉菜单默认选中添加时选中的情况
}
else
{
this.pdiscount1.SelectedValue = "不打折";
}
}
//动态的值时下拉菜单默认选中添加时选中的情况
//读取所有类别,并显示原来所选类别
OleDbDataAdapter d = new OleDbDataAdapter();
d.SelectCommand = new OleDbCommand("select typename from ProductType where typename<>'请选择'", conn);
DataSet rst = new DataSet();
d.Fill(rst,"ProductType");
this.typename1.DataTextField = "typename";
this.typename1.DataValueField = "typename";
this.typename1.DataSource = rst.Tables["ProductType"];
this.typename1.DataBind();
this.typename1.SelectedValue = Session["typenameok"].ToString();
conn.Close();
}
catch
{
Response.Write("参数错误!");
Response.End();
}
代码贴不上来,奇怪,发信息给我吧
1、下拉框是固定的值,修改时要将添加时选的值读出来并选中,比如用户注册时的省份
2、下拉框是动态读取的,修改时要选中添加时的选项,如修改产品时,类别是动态读取的,要选中添加产品的那个类别
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Server.MapPath(@"..\App_Data\Product.mdb"));
try
{ //根据传来的产品pid到产品表中表查询产品,并读出来
if (Request.QueryString["pid"] != null)
{
Session["pid2"] = Request.QueryString["pid"].ToString();
}
else
{
Response.Write("参数错误!");
Response.End();
}
//Session["pid2"] = Convert.ToString(Request.QueryString["pid"].Trim());
OleDbConnection conn = dbconn.createProductConnectionInAdmin();
conn.Open();
OleDbCommand cmdr = new OleDbCommand("select * from Product where pid='" + Convert.ToString(Session["pid2"])+"'", conn);
OleDbDataReader rs = cmdr.ExecuteReader();
if (rs.Read())
{
if (rs["pdiscount"].ToString() !="0")//折扣一般是固定的
{
this.pdiscount1.SelectedValue = rs["pdiscount"].ToString(); //固定值时下拉菜单默认选中添加时选中的情况
}
else
{
this.pdiscount1.SelectedValue = "不打折";
}
}
//动态的值时下拉菜单默认选中添加时选中的情况
//读取所有类别,并显示原来所选类别
OleDbDataAdapter d = new OleDbDataAdapter();
d.SelectCommand = new OleDbCommand("select typename from ProductType where typename<>'请选择'", conn);
DataSet rst = new DataSet();
d.Fill(rst,"ProductType");
this.typename1.DataTextField = "typename";
this.typename1.DataValueField = "typename";
this.typename1.DataSource = rst.Tables["ProductType"];
this.typename1.DataBind();
this.typename1.SelectedValue = Session["typenameok"].ToString();
conn.Close();
}
catch
{
Response.Write("参数错误!");
Response.End();
}
代码贴不上来,奇怪,发信息给我吧
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
展开全部
textbox1.Text=dropdownlist1.Item[dropdownlist1.SelectedIndex].text
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
textbox1.Text = dropdownlist1.SelectedValues.Text
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应调用方法:selectedValues
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询