C# .NET - please clear error

Asked By selva kumar on 16-Jul-12 06:26 AM
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
        FillCountry();
      }

    }

    protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e)
    {
      int Train_no = Convert.ToInt32(ddlTest.SelectedValue.ToString());
      FillStates(Train_no);
      Train_name.SelectedIndex = 0;
    }
    private void FillCountry()
    {
      string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
      SqlConnection con = new SqlConnection(strConn);
      SqlCommand cmd = new SqlCommand();
      cmd.Connection = con;
      cmd.CommandType = CommandType.Text;
      cmd.CommandText = "SELECT Train_no, Train_name,Train_sta,Train_std FROM Train_details";
      DataSet objDs = new DataSet();
      SqlDataAdapter dAdapter = new SqlDataAdapter();
      dAdapter.SelectCommand = cmd;
      con.Open();
      dAdapter.Fill(objDs);
      con.Close();
      if (objDs.Tables[0].Rows.Count > 0)
      {
        ddlTest.DataSource = objDs.Tables[0];
        ddlTest.DataTextField = "Train_no";
        txtTest.DataValueField = "Train_name";
        txtsta.DataTextField = "Train_sta";
        txtstd.DataValueField = "Train_std";
        ddlCountry.DataBind();
        ddlCountry.Items.Insert(0, "--Select--");
      }
      else
      {
        lblMsg.Text = "No Countries found";
      }


    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
      Response.Write(e.CommandName);
    }

}




Eroor:



Server Error in '/Truecolordisplay' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'SelectedValue' does not exist in the current context

Source Error:

Line 26:     protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e)
Line 27:     {
Line 28:         int Train_no = Convert.ToInt32(SelectedValue.ToString());
Line 29:         FillStates(Train_no);
Line 30:         Train_name.SelectedIndex = 0;

Source File: e:\Truecolordisplay\Default.aspx.cs    Line: 28






Version Information: Microsoft .NET Framework Version:2.0.50727.3625; ASP.NET Version:2.0.50727.3634
Robbe Morris replied to selva kumar on 16-Jul-12 08:12 AM
ddlTest.SelectedValue.ToString()

By the way, you need to start posting more descriptive subjects for your question.  "Please help" isn't going to cut it.
Jitendra Faye replied to selva kumar on 16-Jul-12 09:39 AM
First check that what is the value of -

SelectedValue.ToString()

and check that can that value converted to int type or not.
Peter Bromberg replied to selva kumar on 16-Jul-12 12:05 PM

  int Train_no = Convert.ToInt32(ddlTest.SelectedValue.ToString());