本来就不同的,你先把DataGrid邦定一个DataSet
然后再由DataGrid的每一行中找到DropDownList控件,
再把它跟数据邦定

解决方案 »

  1.   

    this is a simple e.f:
    you try:
    1)在该DataGrid添加:OnItemDataBound="Grid_ItemDataBound"
      添加模板列中,其中:
    ...
    <ASP:TEMPLATECOLUMN HeaderText="机构信息">
    <ITEMTEMPLATE>
    <ASP:DROPDOWNLIST id="DropDownList1" Runat="server"></ASP:DROPDOWNLIST>
    </ITEMTEMPLATE>
    </ASP:TEMPLATECOLUMN>
    ...2)Add EVENT HANDLERS:
    protected void Grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemIndex>=0)
    {
    DropDownList myDropDownList = (DropDownList)e.Item.FindControl("DropDownList1");
    //查找数据并绑定到dt
    SqlConnection oConn = new SqlConnection(m_connString);
    SqlCommand cmd = new SqlCommand("select mc,id from your table",oConn);
    oConn.Open();SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    myDropDownList.DataSource = dr ;
    myDropDownList.SelectedIndex = 0;
    myDropDownList.DataTextField ="mc";
    myDropDownList.DataValueField="id";
    myDropDownList.DataBind();
    dr.Close();
    }
    }
      

  2.   

    分别绑定就是了,举个例子
    datagird绑定的是  DS1dropdownlist(DS2)<EditItemTemplate>
    <asp:DropDownList id=DropDownList1 runat="server" Width="204px" Height="22px" datasource="<%# DS2 %>" DataMember="cities" DataValueField="city" DataTextField="city" AutoPostBack="True" OnSelectedIndexChanged="MyChanged">
    </asp:DropDownList>
    </EditItemTemplate>
      

  3.   

    我的几段代码如下,希望高手帮我看看:Private Sub CreatDataSet() '生成datagird数据连接
            MyConn = New OleDbConnection("Provider=MSDAORA.1;Password=test;User ID=test;Data Source=ora9ierp_hj")
            myAdpter.SelectCommand = New OleDbCommand("select * from W_DEPT_STORY ", MyConn) '取得数据来源中的记录
            myAdpter.Fill(mySet, "W_DEPT_STORY")
        End SubPrivate Sub CreatDataDSet() '生成DropDownList数据连接
            MyDConn = New OleDbConnection("Provider=MSDAORA.1;Password=test;User ID=test;Data Source=ora9ierp_hj")
            myDAdpter.SelectCommand = New OleDbCommand("select * from W_DEPT ", MyDConn) '取得数据来源中的记录
            myDAdpter.Fill(myDSet, "W_DEPT")
        End Sub'添加DropDownList的语句及设置
    <EditItemTemplate>
         <asp:DropDownList id=DropDownList1 runat="server" Width="133px" DataSource="<% # myDset %>" DataTextField="DEPT_NAME" DataValueField="DEPT_NAME" DataMember="W_DEPT"></asp:DropDownList>'表格编辑事件
    Private Sub G_history_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles G_history.EditCommand
            G_history.EditItemIndex = e.Item.ItemIndex
    '下句出错,未将对象引用设置到对象的实例。
            G_history.DataSource = mySet.Tables("W_DEPT_STORY").DefaultView
            G_history.DataBind()我这样设置为什么出错呀    End Sub
    </EditItemTemplate>
      

  4.   

    在我发给你的例子里面ComboInGrid.aspx里面就有。
      

  5.   

    不是你的设置出错,是mySet在edit的时候没有实例,这是因为asp.net不会为你保存mySet,你需要将fill后的数据保存在某个地方(Session,或者ViewState).
      

  6.   

    请教niwalker:
    在哪个地方保存mySet呢?我在CreatDataSet() 里加了一句Me.Session("MyDataSet") = mySet,然后:
    Private Sub G_history_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles G_history.CancelCommand
            G_history.EditItemIndex = -1
            mySet = Session("MyDataSet")
            G_history.DataSource = mySet.Tables("W_DEPT_STORY").DefaultView
            G_history.DataBind()
        End Sub怎么提示:
    IListSource 不包含任何数据源。
      

  7.   

    ayine(原振侠) :
    请指教。