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. Dropdown list to populate a gridview

Dropdown list to populate a gridview

Scheduled Pinned Locked Moved ASP.NET
csharpcssasp-netsharepointlinq
2 Posts 1 Posters 0 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.
  • P Offline
    P Offline
    pmcm
    wrote on last edited by
    #1

    hi - i'm working on an asp.net page that has a DDL and depending on the DDL selection will display a gridview of results. Here's the code I have so far:

    Code:
    <%@ Page Title="GDNI_SalesmanManager" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="GDNI_SalesmanManager.aspx.cs" Inherits="GDNI_Salesman_Manager.About" %>

    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <style type="text/css">
    .style1
    {
    width: 251px;
    height: 120px;
    }
    </style>
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
    Customer:
    <asp:DropDownList ID="ddlCustomers" runat="server" Height="17px"
    ToolTip="Customers" Width="285px">
    </asp:DropDownList>
    </h2>
    <p>
     <asp:GridView ID="gvProductClass" runat="server">
    </asp:GridView>
    </p>
    </asp:Content>

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;

    namespace GDNI_Salesman_Manager
    {
    public partial class About : System.Web.UI.Page
    {
    string strConnString = ConfigurationManager.ConnectionStrings["BB_Datawarehouse_DB"].ConnectionString;
    string str;
    SqlCommand com;

        protected void Page\_Load(object sender, EventArgs e)
        {
            ddlCustomers.AutoPostBack = true;
    
            if (!IsPostBack)
            Populate\_ddlCustomers();
        } //in debug mode the code skips to site.master page load event
    
    
        public void Populate\_ddlCustomers()
        {
            ddlCustomers.Items.Add("Please Select a Customer");
            SqlConnection con = new SqlConnection(strConnString);
            con.Open();
            str = "exec dbo.sp\_GetCustNumAndDSeq";
            com = new SqlCommand(str, con);
            SqlDataReader reader = com.ExecuteReader();
            while (reader.Read())
            {
                ddlCustomer
    
    P 1 Reply Last reply
    0
    • P pmcm

      hi - i'm working on an asp.net page that has a DDL and depending on the DDL selection will display a gridview of results. Here's the code I have so far:

      Code:
      <%@ Page Title="GDNI_SalesmanManager" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
      CodeBehind="GDNI_SalesmanManager.aspx.cs" Inherits="GDNI_Salesman_Manager.About" %>

      <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
      <style type="text/css">
      .style1
      {
      width: 251px;
      height: 120px;
      }
      </style>
      </asp:Content>
      <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
      <h2>
      Customer:
      <asp:DropDownList ID="ddlCustomers" runat="server" Height="17px"
      ToolTip="Customers" Width="285px">
      </asp:DropDownList>
      </h2>
      <p>
       <asp:GridView ID="gvProductClass" runat="server">
      </asp:GridView>
      </p>
      </asp:Content>

      using System;
      using System.Data;
      using System.Configuration;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Data.SqlClient;

      namespace GDNI_Salesman_Manager
      {
      public partial class About : System.Web.UI.Page
      {
      string strConnString = ConfigurationManager.ConnectionStrings["BB_Datawarehouse_DB"].ConnectionString;
      string str;
      SqlCommand com;

          protected void Page\_Load(object sender, EventArgs e)
          {
              ddlCustomers.AutoPostBack = true;
      
              if (!IsPostBack)
              Populate\_ddlCustomers();
          } //in debug mode the code skips to site.master page load event
      
      
          public void Populate\_ddlCustomers()
          {
              ddlCustomers.Items.Add("Please Select a Customer");
              SqlConnection con = new SqlConnection(strConnString);
              con.Open();
              str = "exec dbo.sp\_GetCustNumAndDSeq";
              com = new SqlCommand(str, con);
              SqlDataReader reader = com.ExecuteReader();
              while (reader.Read())
              {
                  ddlCustomer
      
      P Offline
      P Offline
      pmcm
      wrote on last edited by
      #2

      here's the answer to my question; I didn't have the OnSelectedIndexChanged="ddlCustomers_SelectedIndexChanged" property set in the ASP properties of the drop down list

      Code:
      <asp:DropDownList ID="ddlCustomers" runat="server"
      Height="17px" Width="285px"
      ToolTip="Customers"
      AppendDataBoundItems="true"
      OnSelectedIndexChanged="ddlCustomers_SelectedIndexChanged">
      <asp:ListItem >Please Select a Customer</asp:ListItem>
      </asp:DropDownList>

      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