如何使用值成员和显示下拉列表成员 [英] how to use value member and display member of dropdownlist

查看:92
本文介绍了如何使用值成员和显示下拉列表成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个表1)Categorycrt 2)Itemcrt 3)Pricefix



categorycrt表有一个主键ProductId

Itemcrt表有一个primarykey ItemId

Pricefix表有一个主键PriceId和两个来自categorycrt表的外来键ProductId和来自Itemcrt表的ItemId



在设计页面上pricefix我有Item的下拉列表和Product的另一个下拉列表。

从下拉列表中选择类别和项目我想输入相应的itemId和ProductId到价格修复表



我想要的是通过选择项目下拉列表,Itemcrt表的相应ItemId(主键)应该插入到Pricefix表的ItemId(外键)中......



请尽快帮助我

解决方案

int itemid = convert.toint32(itemdropdownlist.selectvalue);

然后是i的instert值数据库中的temid。


 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();

}



通过向datavalue字段提供值,将插入相应的数据表primarykey .....但应使用dropdown.selectedvalue


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

解决方案

int itemid = convert.toint32(itemdropdownlist.selectvalue);
and then instert value of itemid in database.


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


这篇关于如何使用值成员和显示下拉列表成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆