DataGrid1 中的其中3列是  productid(产品编号),price(价格),year(年限)
                          AK41                    200          1
                          AK41                    400          2
                          AK41                    550          3
                          AK42                    250          1
                          AK42                    500          2
每种产品的价格是和不同的年限关联的;
我想把年限列做成模板列,是下拉列表式的,当我选择不同的年限时候,价格会对应的改变。
不知道该如何做?(如果您会PB的话,其实就是类似数据子窗口的问题)
我有两点不明白,首先当我选择不同的年限时候触发什么事件?其次我如何把每种产品的年限从数据库读取到年限列的下拉列表中?
如果您有别的解决类似问题的方法也行。

解决方案 »

  1.   

    你可以对年限设计一个模板列,查询时用label 或 textbox 控件,编辑时用下拉框 如DropDownList在DataGrid 的ItemDataBound事件中
    private void DDList_ItemDataBound(object sender,...)
    {
    if(e.Item.ItemType == ListItemType.Edit)
    {
    DropDownList DDList=(DropDownList)e.Item.FindControl("DDList");//括号中的DDList:你在模板列的编辑列上定义的DropDownList名称 
    string Str="select year from T_table";//aa为
    SqlConnect Conn=new SqlConnect(DBaseStr);
    SqlCommand Cmd=new SqlCommand(Str,Conn);
    SqlDatdReader Dr=new SqlDatdReader;
    Dr=Cmd.ExecuteReader();
    while (Dr.Reader())
    {
        DDList.Items.Add(Dr[year].ToString)
    }
    }
    }
    至于选种年限时价格跟着变化,你在DDList的点击事件中编段程序试一试。
      

  2.   

    DDList的点击事件是什么事件?有吗?
      

  3.   

    至于选中年限时价格跟着变化
    1.首先须在.aspx页面中,放datagrid,再在模板列中放的dropdownlsit.
    2.在dropdownlist的OnselectIndexChanged事件中可以取出dropdownlist中的值
    public void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
    MyDropDownList ddl = (MyDropDownList)sender;
    Page.Response.Write(ddl.selectindex);
    }
    如果是用用户控件,我现在还没想出什么好办法.
      

  4.   

    如果不行,在.aspx页面的html页面里把onselectindexchanged=ddl_selectedindexchanged这个事件加上,就如以前的onclick类似.
    ddl_selectedindexchanged事件必须是public
      

  5.   

    1。选择不同年限时DropDownList的autoPostBaxk=true在DropDownList_SelectedIndexChanged事件里处理。
    2。不同的产品年限加入下拉列表我从前这么做过你看你用的上不,建一个Web控件里面只有一个下拉列表,一个属性字段,当datagrid绑定时用模板列绑定这个控件。
    绑定代码:<uc1:Control_color id=Control_color1 runat="server" Prod_ID='<%# DataBinder.Eval(Container, "DataItem.Prod_id")%>'></uc1:Control_color>
    控件代码:        public string Prod_ID
    {
                          set{ViewState["prod_id"] = value;}
                       }
    private void Page_Load(object sender, System.EventArgs e)
    {

    if(!Page.IsPostBack)
    {
    SqlConnection Con1 = new Conn().NewCon();
    Con1.Open();
    string Sql = "select color  from product_color where Pro_id = " + (string)ViewState["prod_id"];
    SqlCommand Cmd = new SqlCommand(Sql,Con1);
    SqlDataReader Dr = Cmd.ExecuteReader();
    while(Dr.Read())
    {
    DropDownList1.Items.Add(Dr["color"].ToString());
    }
    }
    }
      

  6.   

    上面的代码不能使用datagrid的分页,分页需要自己写