前端控件:
<label>发布栏目:<asp:dropdownlist id="sectiondropdownlist" runat="server"></asp:dropdownlist></label
数据绑定:
sourcedb dropdwonlistdata = new sourcedb();
string dropdwonselect = "select * from [section]";
sectiondropdownlist.datasource = dropdwonlistdata.datasetdb(dropdwonselect).tables[0].defaultview;
sectiondropdownlist.datatextfield = "name";
sectiondropdownlist.datavaluefield = "code";
sectiondropdownlist.databind();
button事件:
string newstitle = sectiondropdownlist.selectedvalue;
response.write(newstitle);
问题分析: 因为在page_load中每次都绑定了数据源,而去调用button事件时,实际是每次都刷新了页面的,于是每次在打印出来前都是初始化的值,于是每次都是输出的的一个值。
问题解决: 判断是否是页面回调。
前端控件:
<label>发布栏目:<asp:dropdownlist id="sectiondropdownlist" runat="server"></asp:dropdownlist></label
数据绑定:
if(!ispostback){
sourcedb dropdwonlistdata
= new sourcedb();
string dropdwonselect = "select * from [section]";
sectiondropdownlist.datasource = dropdwonlistdata.datasetdb(dropdwonselect).tables[0].defaultview;
sectiondropdownlist.datatextfield = "name";
sectiondropdownlist.datavaluefield = "code";
sectiondropdownlist.databind();
}
button事件:
string newstitle = sectiondropdownlist.selectedvalue;
response.write(newstitle);