Hi ,
DataClassesDataContext Db = new DataClassesDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var result = from x in Db.cates
select x;
DropDownList1.DataSource = result;
DropDownList1.DataTextField = "cate1";
DropDownList1.DataValueField = "id";
DropDownList1.DataBind();
var resultItem = from x in Db.Items
select x;
DropDownList2.DataSource = resultItem;
DropDownList2.DataTextField = "Item_name";
DropDownList2.DataValueField = "item_code";
DropDownList2.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
var result = (from x in Db.Items
where x.item_code == Convert.ToInt32(DropDownList1.SelectedValue)
select x).Single();
DropDownList2.SelectedValue = result.item_code.ToString();
}
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</div>
Best Regards
M.Mitwalli