dropdownlist插入数据库出错

ruan_hg 2007-06-11 01:01:48
将其selectedvalue插入到数据库的时候,发现永远都是最上面那个选项的值,选择其他值然后提交,库里还是第一个的值,好奇怪
...全文
511 21 打赏 收藏 转发到动态 举报
写回复
用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
  • 打赏
  • 举报
回复
代码?

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧