<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField HeaderText="姓名" />
            <asp:TemplateField HeaderText="班次">
              <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server">
                    </asp:DropDownList>
             </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                 <ItemTemplate>
                  <asp:Button ID="Button2" runat="server" Text="获取" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
</asp:GridView>当我点击 ”获取“按钮时 怎么获取  GridView 当前行 DropDownList 控件的值

解决方案 »

  1.   

    用Eval()方法绑定一下就行了.
      

  2.   

    恐怕用Button 下面的一个属性叫CommandName 可以解决这个问题..
    先将CommandName = "GetValue"
    然后再在GridView里面添加一个RowCommand 事件..
    在里面写一个判断语句
    if(e.CommandName == "GetValue")
    {
       //处理语句
    }这样就获取到DropDownList里面的值了...
      

  3.   

    在RowCommand 事件.. 
    怎么获取当 当前行 DropDownList 控件值
      

  4.   

    不知道是不是要这样的
    先设置Button2的CommandName,CommandArgument
    DropDownList ddl = (DropDownList)GridView1.Rows[e.CommandArgument].FindControl("DropDownList1");
    .....
      

  5.   

    6楼正解....
    DropDownList ddl = (DropDownList)GridView1.Rows[e.CommandArgument].FindControl("DropDownList1");
      

  6.   


                  <asp:TemplateField>
                        <ItemTemplate>
                            <asp:DropDownList ID="ddl" runat="server" Width="100px">
                                <asp:ListItem>a</asp:ListItem>
                                <asp:ListItem>b</asp:ListItem>
                                <asp:ListItem>c</asp:ListItem>
                            </asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Button ID="Button1" runat="server" Text="Button" CommandName="select" />
                        </ItemTemplate>
                    </asp:TemplateField>
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowIndex != -1)
                {
                    int id = e.Row.RowIndex;
                    Button btn = (Button)e.Row.FindControl("Button1");
                    btn.CommandArgument = id.ToString();
                }
            }        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                if (e.CommandName == "select")
                { 
                    int rowIndex = Convert.ToInt32(e.CommandArgument);
                    DropDownList ddl=GridView1.Rows[rowIndex].Cells[6].FindControl("ddl") as DropDownList;
                    string ddlValue = ddl.SelectedItem.Text.Trim();
                }
            }
      

  7.   

    如上楼,在rowcomman事件中,获取DropDownList相应的值,完成正确,给楼上的加分...