社区
C#
帖子详情
dropdownlist插入数据库出错
ruan_hg
2007-06-11 01:01:48
将其selectedvalue插入到数据库的时候,发现永远都是最上面那个选项的值,选择其他值然后提交,库里还是第一个的值,好奇怪
...全文
511
21
打赏
收藏
dropdownlist插入数据库出错
将其selectedvalue插入到数据库的时候,发现永远都是最上面那个选项的值,选择其他值然后提交,库里还是第一个的值,好奇怪
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
21 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
q卡卡p
2007-06-11
打赏
举报
回复
应该是被覆盖了
sowenxiong
2007-06-11
打赏
举报
回复
看看页面的生存周期
当你提交时你的页面会重绘。
在Page_Load 中加入 !Page.IsPostBack 应该就没问题了。
ruan_hg
2007-06-11
打赏
举报
回复
解决了,就是ispostback单位问题
-过客-
2007-06-11
打赏
举报
回复
DropDownList1.Attributes.Add("onchange", "get_text(this)");
get_text干嘛的
贴下它的代码看看
冷月孤峰
2007-06-11
打赏
举报
回复
在pageload事件中加:
if (!Page.IsPostBack)
{
//这里写你的代码
}
flyin2006
2007-06-11
打赏
举报
回复
提交代码?
猜测是你选择 然后提交 然后 有Page_Load 所以又选了第一个
commandosvvv
2007-06-11
打赏
举报
回复
....这得代码好像没什么问题。
你是说你在选择的时候,数据库接收到的不是你选的值,而是第一个值?
那你提交的那部分怎么写的?
ruan_hg
2007-06-11
打赏
举报
回复
我在前台页面上选择了一个值然后提交页面,发现数据库里面的不是我选的那个值而始终是下拉菜单第一项的值
flyin2006
2007-06-11
打赏
举报
回复
try
:
if (!Page.IsPostBack)
{
string s;
if (Session["UserName"] != null)
{
s = Session["UserName"].ToString();
SqlConnection myConnection = new SqlConnection(@"user id=sa;password=zym640227;initial catalog=tempdb;data source=10.0.6.19;Connect Timeout=30");
myConnection.Open();
SqlDataAdapter sda = new SqlDataAdapter("select dw from lianxi_dw where uid=@m_tt", myConnection);
sda.SelectCommand.Parameters.Add(new SqlParameter("@m_tt", SqlDbType.Char, 30)).Value = s;
DataTable dt = new DataTable();
sda.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "dw";
DropDownList1.DataValueField = "dw";
DropDownList1.DataBind();
myConnection.Close();
}
else
Response.Redirect("login.aspx");
RadioButton1.Attributes.Add("onclick", "document.getElementById('td1').style.display='none';document.getElementById('td2').style.display='none'");
RadioButton2.Attributes.Add("onclick", "document.getElementById('td1').style.display='';document.getElementById('td2').style.display=''");
RadioButton3.Attributes.Add("onclick", "document.getElementById('td3').style.display='none';document.getElementById('td4').style.display='none'");
RadioButton4.Attributes.Add("onclick", "document.getElementById('td3').style.display='';document.getElementById('td4').style.display=''");
RadioButton5.Attributes.Add("onclick", "document.getElementById('td5').style.display='none';document.getElementById('td6').style.display='none'");
RadioButton6.Attributes.Add("onclick", "document.getElementById('td5').style.display='';document.getElementById('td6').style.display=''");
RadioButton13.Attributes.Add("onclick", "document.getElementById('td7').style.display='none'");
RadioButton14.Attributes.Add("onclick", "document.getElementById('td7').style.display=''");
DropDownList1.Attributes.Add("onchange", "get_text(this)");
Button1.Attributes.Add("onclick", "return AddCheck();");
}
flyin2006
2007-06-11
打赏
举报
回复
你是讲每次DropDownList绑定的都是一样的?
ruan_hg
2007-06-11
打赏
举报
回复
string s;
if (Session["UserName"] != null)
{
s = Session["UserName"].ToString();
SqlConnection myConnection = new SqlConnection(@"user id=sa;password=zym640227;initial catalog=tempdb;data source=10.0.6.19;Connect Timeout=30");
myConnection.Open();
SqlDataAdapter sda = new SqlDataAdapter("select dw from lianxi_dw where uid=@m_tt", myConnection);
sda.SelectCommand.Parameters.Add(new SqlParameter("@m_tt", SqlDbType.Char, 30)).Value = s;
DataTable dt = new DataTable();
sda.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "dw";
DropDownList1.DataValueField = "dw";
DropDownList1.DataBind();
myConnection.Close();
}
else
Response.Redirect("login.aspx");
RadioButton1.Attributes.Add("onclick", "document.getElementById('td1').style.display='none';document.getElementById('td2').style.display='none'");
RadioButton2.Attributes.Add("onclick", "document.getElementById('td1').style.display='';document.getElementById('td2').style.display=''");
RadioButton3.Attributes.Add("onclick", "document.getElementById('td3').style.display='none';document.getElementById('td4').style.display='none'");
RadioButton4.Attributes.Add("onclick", "document.getElementById('td3').style.display='';document.getElementById('td4').style.display=''");
RadioButton5.Attributes.Add("onclick", "document.getElementById('td5').style.display='none';document.getElementById('td6').style.display='none'");
RadioButton6.Attributes.Add("onclick", "document.getElementById('td5').style.display='';document.getElementById('td6').style.display=''");
RadioButton13.Attributes.Add("onclick", "document.getElementById('td7').style.display='none'");
RadioButton14.Attributes.Add("onclick", "document.getElementById('td7').style.display=''");
DropDownList1.Attributes.Add("onchange", "get_text(this)");
Button1.Attributes.Add("onclick", "return AddCheck();");
hxshanji
2007-06-11
打赏
举报
回复
贴下你pageload的代码..
ruan_hg
2007-06-11
打赏
举报
回复
pageload中没有ispostback请问应该加什么代码进去?
impeller
2007-06-11
打赏
举报
回复
ViewState有没有关闭了
xingxing2378
2007-06-11
打赏
举报
回复
isPostBack 中!!!!!
-过客-
2007-06-11
打赏
举报
回复
楼上,复制那么多干嘛,吓人哪
郁闷啊,从早上逛到现在,就只有一个帖子把问题描述清楚了,我还不会-_-#,其它的,不说什么了............
flyin2006
2007-06-11
打赏
举报
回复
回复人:CathySun118(斯年) ( 两星(中级)) 信誉:100 2007-06-11 13:19:15 得分:0
?
代码?
Top
回复人:lxcnn(过客) ( 两星(中级)) 信誉:100 2007-06-11 13:23:55 得分:0
?
贴你的代码
============
会把他吓坏的
hxshanji
2007-06-11
打赏
举报
回复
在page_load中初始化了dropdownlist的数据了吧.
放到!IsPostBack判断里面去做初始化.
-过客-
2007-06-11
打赏
举报
回复
贴你的代码
CathySun118
2007-06-11
打赏
举报
回复
代码?
C#编程经验技巧宝典
4 <br>0008 为程序设置版本和帮助信息 4 <br>0009 设置Windows应用程序启动窗体 5 <br>0010 设置Web应用程序起始页 5 <br>0011 如何设置程序的
出错
窗口 5 <br>0012 如何进行程序调试 6 ...
C# ASP.NET
DROPDOWNLIST
控件绑定
数据库
,用
DropDownList
1.SelectedValue.ToString 读取的选项值始终是第一项的值的解决方法
1、C# ASP.NET
DROPDOWNLIST
控件绑定
数据库
,
数据库
内容如下
数据库
有3个字段:id,name,map。
数据库
只有1个表,表名为 table1 2、前台代码如下: <asp:
DropDownList
ID="
DropDownList
1" runat=...
处理大并发下的
dropdownlist
数据关联
最近开发一个特殊的ASP.NET应用程序,...通过用户选择关联的数据将结果
插入
到
数据库
中,但是在实际的使用中多次都出现了少量结果关联不上的情况,例如选湖北省武汉市,但
插入
到库中后,市级数据里关联的结果却是北...
怎么从
数据库
里动态获取数据放置select 标签里
或者用
dropdownlist
+ajax控件+webservice实现异步加载。都可以 先创建option标签,再将查询的数据添加到option中所有的步骤我都懂,关键是怎么写啊?还有我不用ajax 就是硬的。select 是不是runat=server...
ASP.net 中遇到的gridview及formview问题集锦
11、使用
dropdownlist
等列表项控件时,明明databind的项就在列表项里,但就是调试就是显示选择项没在列表项中? 答:很可能是SQL
数据库
中的对应列类型是nvar而不是nvarchar型。 12、treeview在Formview中不...
C#
110,571
社区成员
642,565
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章