在回发中保留动态下拉列表的值

编程入门 行业动态 更新时间:2024-10-26 10:27:07
本文介绍了在回发中保留动态下拉列表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有个问题.. 我已经将数据库(sqlserver 2008 express)中的数据动态地绑定到了一个下拉列表.(在VS2010上.每当我将默认值更改为下拉列表中的其他值时……它返回到原始值(而不是选定的值) )....我也尝试在Page Init上编写代码...但是在回发后,它并没有在dropdownbox中显示所有值....请帮助.. 这是代码(dropdownlist autopostback为true) Page_init { ...连接.... da.fill(dt); dropdownlist1.datasource = dt; dropdownlist1.datatextfield ="city" dropdownlist1..databind(); } 问候.

Hi , i have a issue.. i have dynanically bounded the data from the database(sqlserver 2008 express) to a dropdownlist.(on VS2010. Whenever i change the value from default to something else in dropdownlist...it comes back to the original value(and not the selected one)....i tried to write the code on Page Init as well... but then it does not shows the value at all in dropdownbox after postback....Please help.. here is the code(dropdownlist autopostback is true) Page_init { ...connection.... da.fill(dt); dropdownlist1.datasource=dt; dropdownlist1.datatextfield="city" dropdownlist1..databind(); } Regards.

推荐答案

您必须检查是否触发了postback 事件.我在下面放了一些代码. You have to check whether postback event is fired or not. I put some code below. protected override void OnInit(EventArgs e) { base.OnInit(e); if (!IsPostBack) { // Put your logic here. da.fill(dt); dropdownlist1.DataSource=dt; dropdownlist1.DataTextField="city" dropdownlist1.DataValuefield="city" // you may need to add it. dropdownlist1.Databind(); } }

希望对您有帮助.

I hope this helps you well.

if(!ispostback) { sqldataadapter da =新sqldataadapter(从表中选择*",cn); datatable dt = new datatable(); da.fill(dt); dropdownlist1.datasource = dt; dropdownlist1.datatextfield ="col"; dropdownlist1.datavaluefield ="col"; dropdownlist1.databind(); dropdownlist1.items.insert(0,"Select"); } if(!ispostback) { sqldataadapter da=new sqldataadapter("select * from table",cn); datatable dt=new datatable(); da.fill(dt); dropdownlist1.datasource=dt; dropdownlist1.datatextfield="col"; dropdownlist1.datavaluefield="col"; dropdownlist1.databind(); dropdownlist1.items.insert(0,"Select"); }

您需要在回发后重新创建,希望能解决问题 You Need To Recreate again after postback i hope solves the problem

更多推荐

在回发中保留动态下拉列表的值

本文发布于:2023-10-12 21:10:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485906.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态   列表   回发中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!