Note that there are some explanatory texts on larger screens.

plurals
  1. POError with Dropdownlist Control
    text
    copied!<p>In <code>shownotice.aspx</code> page has a Repeater control to show the notice loaded from Database (sql server 2008) and a Dropdownlist control for filtering: <code>all notices</code>(default value = 0)<code>/lecturer's notices</code>(value=1)<code>/ student notices</code> (value=2).</p> <pre><code>&lt;asp:DropDownList ID="DropDownList" runat="server" OnSelectedIndexChanged="DropDownlist_Changed" AutoPostBack="true" &gt; &lt;asp:ListItem Selected="True" Value="0"&gt; All notice &lt;/asp:ListItem&gt; &lt;asp:ListItem Value="1"&gt; Lecturer &lt;/asp:ListItem&gt; &lt;asp:ListItem Value="2"&gt; Student &lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; </code></pre> <p>NOTICE table in database</p> <pre><code> NOTICE(id, title, content,object) </code></pre> <p>object = <code>1</code> --> notice for lecturer</p> <p>object= <code>2</code>--> notice for student.</p> <p>Please take a look at my code below:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bool check = BindRepeater(madoituong, maloai); if (check == false) LabelError.Text = "There is no notice."; } } private bool BindRepeater() { string sql = ""; string key = DropDownList.SelectedValue; if (key == "0") sql = "select * from NOTICE"; else sql = "select * from NOTICE where object=" + key; DataTable tb = EXECUTEQUERYSQL(sql); if (tb.Rows.Count &gt; 0) { Repeater1.DataSource = tb; Repeater1.DataBind(); return true; } else return false; } public void DropDownlist_Changed(Object sender, EventArgs e) { bool check = BindRepeater(); if (check == false) LabelError.Text = "There is no notice."; } </code></pre> <p>All I want is:</p> <ul> <li><p>when client accesses <code>shownotice</code> page -> key= 0 --> Repeater loads all notices in NOTICE table (both for lecturer and for student)</p></li> <li><p>Then client chooses <code>Lecturer</code> or <code>Student</code> to filtering and display notices by object. </p></li> </ul> <p>When I built this page, the program worked fine if it has some notices for lecturer (object=1) and some notices for student (object=2) in Database.</p> <p>But when it only has notices for lecturer or only notices for student--> program worked wrong. </p> <p><strong>For example:</strong></p> <p>There is only one record in NOTICE table:</p> <p>id= 1, title= aaa, content= holiday, object=1 </p> <p>When I choose Lecturer or Student --> it always show notice <code>aaa</code> , it should show messsage "There is no notice" when I choose <code>Student</code> option.</p> <p><strong>Try to debug:</strong></p> <p>When I choose <code>Student</code> option: <code>Datatable tb = null</code> and return <code>false</code>, the program jump into <code>if</code> statement and hit line: LabelError = "There is no notice."; But after finish debugging, the Repeater still shows notice <code>aaa</code> instead of message.</p> <p>Help!!! I really dont know why when I debug, the program hit the line LabelError = "There is no notice."; but then, there is no LabelError Message appear. Help!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload