时间:2021-07-01 10:21:17 帮助过:7人阅读
- <br><label>发布栏目:<asp:DropDownList ID="sectionDropDownList" runat="server"></asp:DropDownList></label <br> <br><strong>数据绑定:</strong> <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>SourceDb DropDwonListData = new SourceDb(); <br>string DropDwonSelect = "SELECT * FROM [Section]"; <br>sectionDropDownList.DataSource = DropDwonListData.DatasetDb(DropDwonSelect).Tables[0].DefaultView; <br>sectionDropDownList.DataTextField = "name"; <br>sectionDropDownList.DataValueField = "code"; <br>sectionDropDownList.DataBind(); <br> <br><strong>Button事件:</strong> <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>string newsTitle = sectionDropDownList.SelectedValue; <br>Response.Write(newsTitle); <br> <br><strong>问题分析:</strong> <br><br>因为在page_load中每次都绑定了数据源,而去调用Button事件时,实际是每次都刷新了页面的,于是每次在打印出来前都是初始化的值,于是每次都是</li></ol></pre>输出的的一个值。 <br><br><strong>问题解决:</strong> <br><br>判断是否是页面回调。 <br><br><strong>前端控件:</strong> <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><label>发布栏目:<asp:DropDownList ID="sectionDropDownList" runat="server"></asp:DropDownList></label <br> <br><strong>数据绑定:</strong> <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>if(!IsPostBack){ <br> SourceDb DropDwonListData <br>= new SourceDb(); <br> string DropDwonSelect = "SELECT * FROM [Section]"; <br> sectionDropDownList.DataSource = DropDwonListData.DatasetDb(DropDwonSelect).Tables[0].DefaultView; <br> sectionDropDownList.DataTextField = "name"; <br> sectionDropDownList.DataValueField = "code"; <br> sectionDropDownList.DataBind(); <br>} <br> <br><br><strong>Button事件: <br></strong><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>string newsTitle = sectionDropDownList.SelectedValue; <br>Response.Write(newsTitle); <br></li><li> </li><li> </li></ol></pre></li></ol></pre></li></ol></pre></li></ol></pre>