Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Populate a date Label with selected value from a dropdownlist in GridView. This is not working.

Populate a date Label with selected value from a dropdownlist in GridView. This is not working.

Scheduled Pinned Locked Moved ASP.NET
csharphtmlhelp
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samflex
    wrote on last edited by
    #1

    Greetings again all and pray that everyone is staying safe. I have a requirement to select a value from a dropdownlist, and upon selecting a value, a label control will be automatically populated with a date value. We are using GridView control. So far, we are running into issues. When I run the code and select a value from the ddlSpeakerName1 dropdownlist control, I get the following error: System.NullReferenceException: 'Object reference not set to an instance of an object.' and the error is on this line:

             txtsDateFilmed1.Text = sdr\["dateAdded"\].ToString();
    

    This is not true. I know I am doing something wrong and would greatly appreciate the assistance as always. Here is some relevant code and select a value //MARKUP

    //C#

    protected void OnDataBound(object sender, EventArgs e)
    {
        DropDownList ddlSpeakerName1 = SermonDetails.FooterRow.FindControl("ddlSpeakerName1") as DropDownList;
        ddlSpeakerName1.DataSource = GetData("SELECT DISTINCT EmployeeID, EmployeeName FROM Employees");
        ddlSpeakerName1.DataTextField = "EmployeeName";
        ddlSpeakerName1.DataValueField = "EmployeeID";
        ddlSpeakerName1.DataBind();
        ddlSpeakerName1.Items.Insert(0, new ListItem("Select Speakers", "0"));
    }
    
    protected void ddlSpeakerName1\_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddlSpeakerName1 = SermonDetails.FooterRow.FindControl("ddlSpeakerName1") as DropDownList;
        TextBox txtsDateFilmed1 = SermonDetails.FooterRow.FindControl("txtsDateFilmed1") as TextBox;
    
        String strConnString = ConfigurationManager.AppSettings\["XPhiasResultString"\].ToString();
        String strQuery = "select dateAdded from Employees where" +
                          " EmployeeID = @employeeID AND dateAdded IS NOT NULL";
        SqlConnection con = new SqlConnection(strConnString);
        SqlCommand cmd = new SqlCommand();
        cmd.Parameters.AddWithValue("@employeeID", ddlSpeake
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups