Click here to Skip to main content
15,915,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
public partial class Default2 : System.Web.UI.Page
{
    SqlConnection con= new SqlConnection();

    protected void Page_Load(object sender, EventArgs e)
    {
        con.ConnectionString = "server=a2ul-pc;uid=sa;pwd=rascal;database=cgrt";

        drop_pcode = pcode;
        drop_fyyear = fyyear;


        if (!IsPostBack)
        {
            FillDropDownList();
        }
    }

    private void FillDropDownList()
    {
        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("select pcode FROM yearly", con);

        myda.Fill(ds);
        drop_pcode.DataSource = ds;
        drop_pcode.DataValueField = "Pcode";
        drop_pcode.DataBind();
        drop_pcode.Items.Insert(0, new ListItem("Select", "0"));
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("Select fyyear from yearly where pcode='"+drop_pcode.SelectedItem.Value+"'",con);
        myda.Fill(ds);
        drop_fyyear.DataSource = ds;
        drop_fyyear.DataValueField = "fyyear";
        drop_fyyear.DataBind();
        drop_fyyear.Items.Insert(0, new ListItem("Select", "0"));
    }
}



when i am executing it the errors that i am getting are:

the name 'drop_pcode' does not exist in current context
the name 'drop_fyyear' does not exist in current context
plus i have enabled autopost back and its giving me error unable to udate auto-refresh 'ajaxcontroltoolkit.dll'. cannot find the assembly 'I:\ajax\AjaxcontrolToolkit.dll'.
plz help me remove my errors i know they are small errors but i m new to programming and debugging is not my strong side.
Posted
Updated 29-Oct-12 19:16pm
v2
Comments
AshishChaudha 30-Oct-12 1:18am    
Provide your HTML Code.

hi friend,

C#
drop_pcode = pcode;
drop_fyyear = fyyear;


write these lines inside the class but not in any method

you declared these lines inside a protected method thats y its showing error

write these lines after the below statement

C#
SqlConnection con= new SqlConnection();


try this.. u may get correct result...
 
Share this answer
 
The following are behaving like as variable not a control name.
XML
<pre lang="cs">
drop_pcode = pcode;
drop_fyyear = fyyear;</pre>


For the problem in unable to udate auto-refresh 'ajaxcontroltoolkit.dll'. Delete the Reference and add it again.


Thanks
 
Share this answer
 
Comments
a2ulthakur 30-Oct-12 1:30am    
<%@ Page Title="" Language="C#" MasterPageFile="~/grid.master" AutoEventWireup="true" CodeFile="yearwiseex.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="Select Project Code">
<asp:DropDownList ID="DropDownList1" runat="server"
style="margin-left: 36px" DataSourceID="SqlDataSource1" DataTextField="pcode"
DataValueField="pcode" Height="20px" Width="131px" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">

                  
<asp:Label ID="Label2" runat="server" Text="Financial Year">
<asp:DropDownList ID="DropDownList2" runat="server" style="margin-left: 52px"
DataSourceID="SqlDataSource2" DataTextField="fyyear" DataValueField="fyyear"
Height="20px" Width="131px">

<asp:Button ID="Button1" runat="server" Text="GO" />


html for my page
a2ulthakur 30-Oct-12 1:32am    
ashish can u plz provide me a solution as to where i shd declare these refrences to name of 'drop_pcode' and 'drop_fyyear'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900