Click here to Skip to main content
15,896,541 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have three table 1) Categorycrt 2)Itemcrt 3) Pricefix

categorycrt table has a primarykey ProductId
Itemcrt table has a primarykey ItemId
Pricefix table has a primarykey PriceId and two foreignkeys ProductId from categorycrt table and ItemId from Itemcrt table

And on the design page for pricefix i have dropdownlist for Item and another dropdownlist for Product.
on selecting the category and item from the dropdownlist i wanted to enter the corresponding itemId and ProductId to the price fix table

what i want is by selecting the item dropdownlist the corresponding ItemId(primary key) of the Itemcrt Table should be inserted in the ItemId(foreign key) of the Pricefix table...

Kindly help me out as soon as possible
Posted
Updated 3-May-14 17:40pm
v3
Comments
José Amílcar Casimiro 3-May-14 13:26pm    
What's the problem?
Ajesh1986 3-May-14 20:43pm    
what i want is by selecting the item dropdownlist the corresponding ItemId(primary key) of the Itemcrt Table should be inserted in the ItemId(foreign key) of the Pricefix table...
[no name] 3-May-14 21:31pm    
Okay and what is preventing you from doing this? What have you tried to do? What is the problem that you have encountered with the code that you have written?
abdul subhan mohammed 3-May-14 14:50pm    
select the dropdownlist selectedvalue n save it, for both the dropdownlist.

eg: itemdropdownlist,
int itemid = convert.toint32(itemdropdownlist.selectedvalue);

hope this will help u.
Ajesh1986 3-May-14 20:42pm    
Thanks for the reply brother,.. actually what i want is by selecting the item dropdownlist the corresponding ItemId(primary key) of the Itemcrt Table should be inserted in the ItemId(foreign key) of the Pricefix table...

int itemid = convert.toint32(itemdropdownlist.selectvalue);
and then instert value of itemid in database.
 
Share this answer
 
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
 
Share this answer
 

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