Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net drop down list not selecting any value
    primarykey
    data
    text
    <p>At btnSave - button event-handler, in the following two lines, SelectedValue is always returning null. </p> <pre><code>not.TargetSessionCode = this.sessionsDropDownList1.SelectedValue; not.CourseCode = this.coursesDropDownList1.SelectedValue; </code></pre> <p>Can anyone say why?</p> <p>This is my aspx code:</p> <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="TeacherComposeNotice.aspx.cs" Inherits="Ice_Web_Portal_v_3_0_WebApplication.Teacher.TeacherComposeNotice" Title="Untitled Page" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt; &lt;table style="width: 270px"&gt; &lt;tr&gt; &lt;td style="text-align: right"&gt; Session:&lt;/td&gt; &lt;td colspan="2"&gt; &lt;asp:DropDownList ID="sessionsDropDownList1" runat="server" Width="178px"&gt; &lt;/asp:DropDownList&gt;&lt;/td&gt; &lt;td colspan="1" style="width: 6px"&gt; &lt;asp:Label ID="userNameLabel" runat="server" Text="usernameLabel" Width="167px"&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="text-align: right"&gt; Courses:&lt;/td&gt; &lt;td colspan="2"&gt; &lt;asp:DropDownList ID="coursesDropDownList1" runat="server" Width="178px"&gt; &lt;/asp:DropDownList&gt;&lt;/td&gt; &lt;td colspan="1"&gt;&lt;asp:Label id="labCourses" runat="server" Width="167px" Text="labCourses"&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="text-align: right"&gt; Subject:&lt;/td&gt; &lt;td colspan="3"&gt; &lt;asp:TextBox ID="mailSubjectTextBox" runat="server" Width="343px"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="text-align: right" valign="top"&gt; Content:&lt;/td&gt; &lt;td colspan="3"&gt; &lt;asp:TextBox ID="mailContentTextBox" runat="server" Height="181px" Width="343px" Font-Names="Verdana"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="text-align: right" valign="top"&gt; Expiry Date :&lt;/td&gt; &lt;td colspan="3"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="text-align: right" valign="top"&gt; &lt;/td&gt; &lt;td colspan="3" style="text-align: center"&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="text-align: right" valign="top"&gt; &lt;/td&gt; &lt;td colspan="3" style="text-align: left"&gt; &lt;asp:Label ID="errorMessageLabel" runat="server" ForeColor="#C00000" Text="***" Width="314px"&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="text-align: right" valign="top"&gt; &lt;/td&gt; &lt;td colspan="3" style="text-align: left"&gt; &lt;asp:Button ID="btnBack" runat="server" OnClick="btnBack_Click" Text="Back" /&gt; &lt;asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/asp:Content&gt; </code></pre> <p>This is my code-behind:</p> <pre><code>public partial class TeacherComposeNotice : System.Web.UI.Page { string username = string.Empty; protected void Page_Load(object sender, EventArgs e) { username = (string)Request.QueryString["username"]; if (!IsPostBack) { LoadAllSessionsToDDL(); LoadAllCoursesToDDL(); } } private void LoadAllSessionsToDDL() { this.sessionsDropDownList1.Items.Clear(); List&lt;Ice_Web_Portal.BO.Session_&gt; items = Ice_Web_Portal.BO.Session_.GetAllSessions(); this.sessionsDropDownList1.DataSource = items; this.sessionsDropDownList1.DataTextField = "SessionName"; this.sessionsDropDownList1.DataValueField = "SessionCode"; this.sessionsDropDownList1.DataBind(); this.sessionsDropDownList1.SelectedIndex = 0; } private void LoadAllCoursesToDDL() { this.coursesDropDownList1.Items.Clear(); List&lt;Course&gt; items = Course.GetCourses(); this.coursesDropDownList1.DataSource = items; this.coursesDropDownList1.DataTextField = "CourseName"; this.coursesDropDownList1.DataValueField = "CourseCode"; this.coursesDropDownList1.DataBind(); } protected void btnBack_Click(object sender, EventArgs e) { Server.Transfer("~/Teacher/TeacherControlPanel.aspx?username=" + username); } protected void btnSave_Click(object sender, EventArgs e) { Ice_Web_Portal.BO.Teacher teacher = Ice_Web_Portal.BO.Teacher.GetTeacherByUsername(username); if (teacher != null) { Notice not = new Notice(); not.HangingDate = DateTime.Now; not.TeacherCode = teacher.TeacherCode; not.TargetSessionCode = this.sessionsDropDownList1.SelectedValue; not.CourseCode = this.coursesDropDownList1.SelectedValue; not.NoticeSubject = this.mailSubjectTextBox.Text; not.NoticeContent = this.mailContentTextBox.Text; not.ExpiryDate = DateTime.Now.AddMonths(1); not.IsExpired = false; bool success = Notice.Save(not); if (success) { errorMessageLabel.Text = "Saved"; } else { errorMessageLabel.Text = "Save failed"; } } else { //labErrorMessage.Text = "No teacher found"; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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