下面的GridView已经进行了数据绑定,如何将模板列DropDownList从另一个数据表查询,得到的DataSet给DropDownList,每一行的下拉菜单内容是一样的。
                    <asp:GridView ID="gdvTemplet" runat="server" BorderColor="#EAE9E6" CellPadding="0"
                        Height="205px" HorizontalAlign="Center" Width="90%" AutoGenerateColumns="False"
                        BorderWidth="1px" OnPreRender="gdvTemplet_PreRender" 
                        onrowdatabound="gdvTemplet_RowDataBound">
                        <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        <Columns>
                            <asp:TemplateField HeaderText="日期">
                                <ItemTemplate>
                                    <asp:Label ID="lbldate" runat="server" Text="Label"></asp:Label>
                                    <br />
                                    <asp:Label ID="lblweek" runat="server" Text="Label"></asp:Label>
                                </ItemTemplate>
                                <HeaderTemplate>
                                    讲师
                                </HeaderTemplate>
                                <ControlStyle Width="115px" />
                                <HeaderStyle Width="115px" />
                            </asp:TemplateField>
                            <asp:BoundField DataField="CourseTime" HeaderText="时间">
                                <ControlStyle Height="177px" />
                                <HeaderStyle Width="177px" />
                            </asp:BoundField>
                            <asp:BoundField DataField="CourseTitle" HeaderText="课程内容">
                                <ControlStyle Width="171px" />
                            </asp:BoundField>
                            <asp:TemplateField HeaderText="讲师">
                                <ItemTemplate>
                                    <asp:DropDownList ID="drop1" runat="server">
                                    </asp:DropDownList>
                                </ItemTemplate>
                                <ControlStyle Width="88px" />
                            </asp:TemplateField>
                            <asp:BoundField DataField="CourseMinute" HeaderText="课时(分钟)">
                                <ControlStyle Height="114px" />
                            </asp:BoundField>
                        </Columns>
                        <HeaderStyle BackColor="#9ABF07" ForeColor="White" Height="26px" HorizontalAlign="Center"
                            VerticalAlign="Middle" />
                    </asp:GridView>

解决方案 »

  1.   

    在RowDataBound事件中查找dropDownList ,找到后绑定它就行了
    e.Row.Cells[dropDownList所在列].FindControl("dropDownList名称")
      

  2.   

            e.Row.Cells[3].FindControl("drop1").DataSource=;
    没有这个属性啊。
      

  3.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 

       if (e.Row.RowType == DataControlRowType.DataRow) 
       { 
          DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1"); 
          ddl.DataSource = ds;
          ddl.DataBind();     } 
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowState == DataControlRowState.Edit || e.Row.RowState == (DataControlRowState.Alternate | DataControlRowState.Edit))
    {
    DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
    if (ddl != null)
    {
    ddl.DataSource = ds;
          ddl.DataBind(); }
    }
    }