.net  现以把数据从数据库中取出来,要把数据邦定到DataGrid中的DropDownList,TextBox中,
DropDownList只有三个值(好,良,差),现在要根据取出来的值对应选择三个中的一个而进行匹配选中。TextBox中则显示姓名,到时候TextBox中的值可以改。
     要实现这样现实怎么做????????????

解决方案 »

  1.   

    DropDownList中的值也可能根据姓名而进行修改??
      

  2.   

    textbox放入模板列的itemtemplate里面!然后和相应字段绑定
    至于dropdownlist,你可以在设计的时候就给他加入3个项目(好良差)
    然后在datagrid的itemdatabound事件里面写如下代码,这个所帮定的字段可以绑定datagrid一个隐藏的帮定列if(e.item.itemindex >=0)
    {
       string c = e.item.cells[i].text.trim;
       DropDownList mydp =(DropDownList)e.item.cells[j].findcontrol("mydropdown");
       if(c == "1")
         mydp.selectitem.text = c;
    ....
    }
      

  3.   

    //****你在DataGrid的模版列中进行处理,然后在后台进行处理//****邦定数据到TextBox中代码为
    <asp:textbox id="txtname" return="server" Text='<%#DataBinder.Eval(Container.DataItem,"Name")%>'/>
    //*****邦定数据到DropDownList控件中,你在模版列放一个DropDownList控件,然后在后台dataitembound事件中进行相应处理.
    //****代码如下
     protected void DGRid_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            //***获取drpState控件
            DropDownList drpState = (DropDownList)e.Item.FindControl("drpState");        //****你可将,先保存的值,放在一个隐藏控件中,然后获取隐藏控件,就可以对DropDownList控件进行默认选择处理了.
            if (drpState != null)
            {
                //****邦寂数据
                DillDropDownList(ref drpState,true,"好");
            }
        }    private void DillDropDownList(ref DropDownList drpList,bool IsBool,string FiledValue)
        {
            drpList.Items.Clear();        if (IsBool == true)
            {
                drpList.Items.Add("请选择");
            }        string strTemp="好,一般,差,很差";
            string[] strTempA = strTemp.Split(',');
            foreach(string str in strTempA)
            {
                ListItem LItem = new ListItem(str, str);            drpList.Items.Add(LItem);
            }        //****构造以前的数据进行相应处理
            for (int i = 0; i < drpList.Items.Count; i++)
            {
                if (drpList.Items[i].Value == FiledValue)
                {
                    drpList.Items[i].Selected = true;
                }
            }
        }