hai all,
i have two comboboxes in one of my .aspx pages when i select a item in one combobox the other should display its concern data , but i am not able to bind the data to other one , iam getting an error called "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Location_Id' ". what do i do to get over this.
can anybody help me.
thanks
Loading
Satyapriya NayakPosted Apr 27, 2012, 6:54 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Cascading_dropdownlist._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Cascading_dropdownlist
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
product();
}
}
void product()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select Productid,Productname from TVOP1";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "TVOP1");
ddlProduct.Items.Clear();
ddlProduct.Items.Add("--Select--");
ddlProduct.DataValueField = "Productid";
ddlProduct.DataTextField = "Productname";
ddlProduct.DataSource = ds;
ddlProduct.DataMember = "TVOP1";
ddlProduct.DataBind();
con.Close();
}
protected void ddlProduct_SelectedIndexChanged(object sender, EventArgs e)
{
productsub();
}
void productsub()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select Productsubid,Productsubname from TVOP2 where Productid='" + ddlProduct.SelectedValue + "'";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "TVOP2");
ddlProductsub.Items.Clear();
ddlProductsub.Items.Add("--Select--");
ddlProductsub.DataValueField = "Productsubid";
ddlProductsub.DataTextField = "Productsubname";
ddlProductsub.DataSource = ds;
ddlProductsub.DataMember = "TVOP2";
ddlProductsub.DataBind();
con.Close();
}
}
}
Thanks
SenthilkumarPosted Apr 27, 2012, 4:29 AM
You are trying to bind the Combox and which you set the DataValueField or DataTextField is not available in the source.
You need to check whether the Location_Id is available in the data source.
Already we have given some example source code for similar kind of tasks.
http://www.c-sharpcorner.com/Forums/Thread/169160/dropdowm-did-not-show-the-value-of-next-one.aspx