hello:想问你们用GridView控件绑定DropDownList下拉列表框是  绑定到是绑定上了 可有个问题,选择是,例如选择班级时,选择的值就没有了,怎么回事???高分求救  在线等  急用!!!!!

解决方案 »

  1.   

    DropDownList也需要邦定数据源。
      

  2.   

    用GridView控件绑定DropDownList下拉列表框是 绑定到是绑定上了 可有个问题,选择是,这是说的什么啊
      

  3.   

    代码:本人用vb.net 2005 数据源现成拖拽的 不是手写的
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyGridview.aspx.vb" Inherits="MyGridview" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table border="3">
                <tr>
                    <td colspan="2">
                        <asp:Label ID="Label1" runat="server" Font-Size="X-Large" ForeColor="Navy" Text="编辑命令数据列(EditCommandColumn)"></asp:Label></td>
                </tr>
                <tr>
                    <td style="width: 100px; height: 45px" valign="top">
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                            DeleteCommand="delete from mytable where id=@id" SelectCommand="SELECT * FROM [mytable]"
                            UpdateCommand="update mytable set name=@name,age=@age,class=@class where id=@id">
                        </asp:SqlDataSource>
                        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                            AutoGenerateDeleteButton="True" AutoGenerateSelectButton="True" BackColor="White"
                            BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="id"
                            DataSourceID="SqlDataSource1" GridLines="Vertical" PageSize="4" Width="500px">
                            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                            <Columns>
                                <asp:BoundField DataField="id" HeaderText="编号" InsertVisible="False" ReadOnly="True"
                                    SortExpression="id" />
                                <asp:BoundField DataField="name" HeaderText="姓名" SortExpression="name" />
                                <asp:BoundField DataField="age" HeaderText="年龄" SortExpression="age" />
                                <asp:BoundField DataField="class" HeaderText="班级" SortExpression="class" />
                            </Columns>
                            <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                            <AlternatingRowStyle BackColor="#DCDCDC" />
                        </asp:GridView>
                    </td>
                    <td style="width: 100px; height: 45px" valign="top">
                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                            InsertCommand="insert into mytable(name,age,class)values(@name,@age,@class)"
                            SelectCommand="select id,name,age,class from mytable where id=@id" UpdateCommand="update mytable set name=@name,age=@age,class=@class where id=@id">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="GridView1" Name="id" PropertyName="SelectedValue" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateEditButton="True" AutoGenerateInsertButton="True"
                            AutoGenerateRows="False" BackColor="White" BorderColor="#999999" BorderStyle="None"
                            BorderWidth="1px" CellPadding="3" DataKeyNames="id" DataSourceID="SqlDataSource2"
                            GridLines="Vertical" Height="50px" Width="125px">
                            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                            <EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                            <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                            <Fields>
                                <asp:BoundField DataField="id" HeaderText="编号" InsertVisible="False" ReadOnly="True"
                                    SortExpression="id" />
                                <asp:BoundField DataField="name" HeaderText="姓名" SortExpression="name" />
                                <asp:BoundField DataField="age" HeaderText="年龄" SortExpression="age" />
                                <asp:TemplateField HeaderText="班级" SortExpression="class">
                                    <EditItemTemplate>
                                        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3"
                                            DataTextField="class" DataValueField="class" SelectedValue='<%# Bind("class", "{0}") %>'>
                                        </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                                            SelectCommand="SELECT DISTINCT [class] FROM [mytable] ORDER BY [class]"></asp:SqlDataSource>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource4"
                                            DataTextField="class" DataValueField="class" SelectedValue='<%# Bind("class", "{0}") %>'>
                                        </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                                            SelectCommand="SELECT DISTINCT [class] FROM [mytable] ORDER BY [class]"></asp:SqlDataSource>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("class", "{0}") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Fields>
                            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                            <AlternatingRowStyle BackColor="#DCDCDC" />
                        </asp:DetailsView>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Label ID="message" runat="server" ForeColor="Red"></asp:Label></td>
                </tr>
            </table>
        
        </div>
        </form>
    </body>
    </html>
      

  4.   

    http://tb.blog.csdn.net/TrackBack.aspx?PostId=673225
      

  5.   

    antiking  你发的什么东西啊??????
    打开以后为:
      <?xml version="1.0" encoding="utf-8" ?> 
    - <response>
      <error>1</error> 
      <message>Sorry, please use post insted of get.</message> 
      </response>
      

  6.   

    private void dgExtractRoles_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) 

     string sql="select port form tb_port";
     SqlDataAdapter sda= new SqlDataAdapter(sql,conn);
     DataSet  myds = new DataSet();
     sda.Fill(myds,"Rus_Port");
     int c = myds.Tables["Rus_Port"].Rows.Count; if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 

    DropDownList ddlport = (DropDownList)e.Item.FindControl("ddl_port"); 
    ddlport.DataSource = myds.Tables["Rus_Port"].DefaultView; 
    ddlport.DataBind(); 

    } protected void ddl_port_SelectedIndexChanged(object sender, EventArgs e)
    {
       DropDownList list = (DropDownList)sender;
     
    }
      

  7.   

    private void dgExtractRoles_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) 

     string sql="select port form tb_port";
     SqlDataAdapter sda= new SqlDataAdapter(sql,conn);
     DataSet  myds = new DataSet();
     sda.Fill(myds,"Rus_Port");
     int c = myds.Tables["Rus_Port"].Rows.Count; if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 

    DropDownList ddlport = (DropDownList)e.Item.FindControl("ddl_port"); 
    ddlport.DataSource = myds.Tables["Rus_Port"].DefaultView; 
    ddlport.DataBind(); 
    ddlport.SelectedIndexChanged+= new System.EventHandler(this.ddl_port_SelectedIndexChanged);

    } protected void ddl_port_SelectedIndexChanged(object sender, EventArgs e)
    {
       DropDownList list = (DropDownList)sender;
     
    }
      

  8.   

    http://weekzero.cnblogs.com/articles/401231.html
      

  9.   

    呵呵 用两个表实现吧 我同事告诉我的,很好用的,班级用一个表,select查询就可以了,试试,祝你成功!!!