protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Fill_Combo();
}
}
private void Fill_Combo()
{
DropDownList2.Items.Clear();
DataTable dt = obj.display1();
DropDownList2.DataSource = dt;
DropDownList2.DataTextField = "ProductCategory";
DropDownList2.DataValueField = "ProductId";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, "--Select--");
DropDownList2.Focus();
DropDownList1.Items.Clear();
DataTable dt1 = obj2.display();
DropDownList1.DataSource = dt1;
DropDownList1.DataTextField = "Itemname";
DropDownList1.DataValueField = "ItemId";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "--Select--");
DropDownList1.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
obj1.ItmId = DropDownList1.SelectedValue;
obj1.PdtId=DropDownList2.SelectedValue;
obj1.Rate=Convert.ToInt32(txtrate.Text);
int res = obj1.save();
}
by providing value to datavalue field the corresponding datatable primarykey will be inserted..... but dropdown.selectedvalue should be used