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