<asp:TemplateField HeaderText="启用状态">
                        <ItemTemplate>
                            <%# Eval("OpenState")%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:HiddenField ID="HDFOpenState" runat="server" Value='<%# Eval("OpenState") %>' />
                            <asp:DropDownList ID="DDLOpenState" runat="server" Width="90px" >
                                <asp:ListItem Value = "开启">开启</asp:ListItem>
                                <asp:ListItem Value = "停止">停止</asp:ListItem>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemStyle Width="10%" />
上面是前台关于模板列使用代码
在编辑更新的时候,即在GridView1_RowUpdating事件处理方法里面可以通过
string strOpenState = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DDLOpenState")).Text.Trim();
方法来获取到值。
我现在要做的是,在非编辑情况下,如何获取该单元格的值?
我尝试了一下两种方法都不行:
1,string strOpenState = GridView1.Rows[e.RowIndex].Cells[4].Text.Trim();
此种方法获取不到该单元格的值,strMediaNum 的结果是 null;
2,string strOpenState = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DDLOpenState")).Text.Trim();
此种情况下由于是在非编辑情况下,会提示FindControl使用错误。
求高手指点asp.net gridview GridViewDropDownListASP

解决方案 »

  1.   

    DropDownList   strOpenState =((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DDLOpenState")).Text.Trim();  楼主这样写试试
      

  2.   

    错了, 应该是, DropDownList   dlist=(DropDownList)GridView1.Rows[e.RowIndex].FindControl("DDLOpenState");
    string strOpenState =dlist.text.Tostring();
      

  3.   

    在编辑状态中能找到
    RowEditing中写执行语句
    RowUpdating找不到
      

  4.   

    like this?
    http://www.cnblogs.com/insus/archive/2013/05/01/3052604.html
      

  5.   

    GridView1_RowUpdating事件,你可以先获取行控件: Control _editControl = _gridView.Rows[e.RowIndex].Cells[_columnIndex].Controls[3]; 通过判断是什么控件获取什么值,比如:
                             if (_editControl is DropDownList)
                            {
                              string strOpenState = ((DropDownList)_editControl).SelectedValue;}具体的Cells[_columnIndex].Controls[3]你自己去设置
      

  6.   

     GridView _gridView = (GridView)sender;        if (e.RowIndex > -1)
            {
    //写在这里面
    }