急!有答案马上结贴!各位老大,关于在修改时的DropDownList问题,如何在进入修改页面时能把数据库里的值传进DropDownList里???
前台
DropDownList只有两个值男和女
然后存入数据库
在点击修改进入另一页面的时候,
如何可以默认显示当初选的值!!!!单个值如何绑定
问题点数:35、回复次数:22Top
1 楼sweet12345(幸福的狗狗)回复于 2004-12-01 10:11:39 得分 0
点击修改的时候,带参数过去 ?Sex=1 或者 ?Sex=0Top
2 楼sweet12345(幸福的狗狗)回复于 2004-12-01 10:13:48 得分 0
1表示男,0表示女,根据参数你就可以知道当初选的值是什么了。参数的只根据你当初的取值得来。
另外,单个值的话,你可以通过
Me.DropDownList1.Items.Add("男")
邦定Top
3 楼tengjian1981(新的一年又来到)回复于 2004-12-01 10:17:28 得分 0
Session或者?Sex="男"传参数;
返回时DropDownList1.SelectedValue="男";Top
4 楼50277(柳影随风)回复于 2004-12-01 10:18:48 得分 0
ddlstBookType.SelectedIndex=ddlstBookType.Items.IndexOf(ddlstBookType.Items.FindByValue(数据库中的值));Top
5 楼50277(柳影随风)回复于 2004-12-01 10:20:21 得分 0
看错了!对不起!Top
6 楼zooo(其实我是个程序员!)回复于 2004-12-01 10:20:48 得分 0
我在数据库里面的参数就是‘男’或是‘女’,
就用类似的方法 string sex=(string)dr["sex"];
Sex.Text =sex;
怎么样绑定到DropDownList上啊???Top
7 楼cynthia36()回复于 2004-12-01 10:32:34 得分 15
将你的DropDownList中和sex字段相同的值的selected属性设为真!
(假设DropDownList的id为DropDownList1)
this.DropDownList1.Items.FindByText(dr["sex"].ToString().Trim()).Selected=true;Top
8 楼wang790809(石头)回复于 2004-12-01 10:33:40 得分 0
(ddl_select.Items.FindByValue(value)).Selected = true;Top
9 楼zooo(其实我是个程序员!)回复于 2004-12-01 10:46:15 得分 0
this.DropDownList1.Items.FindByText(dr["sex"].ToString().Trim()).Selected=true;
我用这个出现错误
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
Top
10 楼therainman(一只郁闷的猪)回复于 2004-12-01 10:55:18 得分 20
呵呵,十天前我也碰到这个问题,和你一样:)
string sex_selected==dr["sex"].ToString();
ListItem itemthis = this.Items.FindByValue(sex_selected);
if (itemthis != null)
{
//已经找到
itemthis.Selected = true;
}
else
{
//没有找到,B表中没有指定的数据
//do nothing
}
加上这一段看看Top
11 楼zooo(其实我是个程序员!)回复于 2004-12-01 11:12:35 得分 0
therainman(一只郁闷的猪)
出现错误说我的类里面不包含对Items的定义啊!Top
12 楼AmaomaoA()回复于 2004-12-01 11:17:27 得分 0
DropDownList.SelectedIndexTop
13 楼gbbword(分不清)回复于 2004-12-01 11:19:49 得分 0
ListItem itemthis = (错误就在这里!====>)this.Items.FindByValue(sex_selected);
ListItem itemthis = this.DropDownList1.Items.FindByValue(sex_selected);Top
14 楼zooo(其实我是个程序员!)回复于 2004-12-01 11:20:18 得分 0
therainman(一只郁闷的猪)
还是不行啊!
能把qq号留给我吗!Top
15 楼therainman(一只郁闷的猪)回复于 2004-12-01 11:21:19 得分 0
你是写在.cs文件中么?要不看看你是不是加上了
<%@ Page Language="C#" Debug="true"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
把你的原码贴上来看看Top
16 楼therainman(一只郁闷的猪)回复于 2004-12-01 11:24:12 得分 0
哦,18231975Top
17 楼zooo(其实我是个程序员!)回复于 2004-12-01 11:26:49 得分 0
源码好大一篇啊
我贴主要的吧
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
DataSet ds = new DataSet();
myCommand.Fill(ds,"adduser");
DataRow dr;
dr=ds.Tables["adduser"].Rows[0] ;
string name=(string)dr["name"];
Name.Text =name;
//string chara=(string)dr["chara"];
// this.Chara.Items.FindByText(dr["chara"].ToString().Trim()).Selected=true;
string Chara=dr["chara"].ToString();
ListItem itemthis =this.Chara.Items.FindByValue;
if (itemthis != null)
{
//已经找到
itemthis.Selected = true;
}
else
{
//没有找到,B表中没有指定的数据
//do nothing
}
Top
18 楼therainman(一只郁闷的猪)回复于 2004-12-01 11:27:15 得分 0
对,
ListItem itemthis = (错误就在这里!====>)this.Items.FindByValue(sex_selected);
ListItem itemthis = this.DropDownList1.Items.FindByValue(sex_selected);
因该是:
ListItem itemthis = this.DropDownList1.Items.FindByText(sex_selected);
Top
19 楼tbmlh(成林)回复于 2004-12-01 15:04:34 得分 0
修改时把值取出来
DropDownList1.DataSource= [DataSource];
DropDownList1.DataTextField="";
DropDownList1.DataValueField="";
DropDownList1.DataBind();
DropDownList1.Items.Insert(O ,男);
DropDownList1.Items[O].Selected =true;
}
看着改一下吧.我这不好输入英文Top
20 楼camark(5天生活)回复于 2004-12-01 15:08:24 得分 0
直接传过去方便点 abcde.aspx?sex=男Top
21 楼jeffidea(程序诗人)回复于 2004-12-01 16:05:46 得分 0
直接传过去 abcde.aspx?sex=男
然后在abcde.aspx的Page_Load中写
foreach(ListItem li in ddlSex)
{
if(li.SelectedValue==Request.QuerryString["sex"])
li.Selected=true;
}Top
22 楼stephenyk(菜鸟)回复于 2004-12-01 16:27:28 得分 0
For Each sexlist In sex.Items
If sexlist.Value = rs.Tables(0).Rows(0).Item("sex") Then
'Response.Write(sexlist.Value)
sexlist.Selected = True
Else
sexlist.Selected = False
End If
NextTop
相关问题
- 100分~~~求助模板列DropDownList绑定数据库中某些字段等~~问题~~~各位老大帮忙
- 弹出页面后,dropdownlist显示的是数据库的值,如何让在页面弹出后,dropdownlist显示的值为空,当选择时,再显示值呢?
- 数据库页面备份问题?????
- dropdownlist里怎样在页面加载的时候自动选择数据库中特定的项,并且数据其他的项也在dropdownlist中?
- TemplateColumn的dropdownlist如何绑定数据库?
- dropdownlist绑定数据库有问题
- 请教已显示页面读取数据库的问题
- 新手:用WEB页面修改数据库中的表?
- 简体数据库在繁体页面如何显示?
- 如何根据数据库内容自动生成页面




