从Grid Row获取所有选定的值

时间:2013-08-21 08:27:25

标签: asp.net listview gridview drop-down-menu checkbox

我有一个gridview(有10行)。每行只包含一列,其中包含1个复选框,2个下拉菜单,1个radiobutton列表。

现在我需要根据选中的复选框将所选值输入List。我的意思是,如果我选中第一个复选框,IList中的第一个值应该具有该复选框的名称及其选定的下拉列表和radiobuttonlist值。

如何实现这一目标?任何人都可以帮我吗?

/* Properties to get selected values */
public string SelectedChekbox
    {
        get { return _selectedChekbox; }
        set { _selectedChekbox = value; }
    }

    public string Ddl1Value
    {
        get { return _ddl1Value; }
        set { _ddl1Value = value; }
    }

    public string Ddl2Value
    {
        get { return _ddl2Value; }
        set { _ddl2Value = value; }
    }


/* This is the property in which I need values*/
public string SelectedGridValues
    {
        get { return _selectedGridValues; }
        set { _selectedGridValues = value; }
    }

/* To get the selected values of grid into list*/
/*** This was incomplete code. Need help to improve this ***/
private IList<MyList> LoadList()
    {

      foreach (DataListItem dlItem in dlDataList.Items)
      {
         GridView grid = (GridView)dlItem.FindControl("gvGridList");
         if (grid != null)
         {
           foreach (GridViewRow gridRow in grid.Rows)
           {
             CheckBox chk = gridRow.FindControl("chkSelect") as CheckBox;
             RadioButton rdo = gridRow.FindControl("rdoSelect") as RadioButton;
             DropDownList ddl1Value = gridRow.FindControl("ddl1") as DropDownList;
             DropDownList ddl1Value = gridRow.FindControl("ddl2") as DropDownList;

               if (chk.Checked && chk.Text == Name)
               {
                            _selectedGraph = chk.Text;
                            _ddl1Value = ddl1.SelectedValue;
                            _ddl1Value = ddl2.SelectedValue;
                        }
                    }
                }
            }

        }

1 个答案:

答案 0 :(得分:0)

gridview被渲染到一个html表,所以尝试用类似firebug的东西检查确切的选择器,但它应该像

var myrows = $(".myTableClass tr").has("input[type=checkbox]:checked");

应仅返回已检查复选框的html表行。

从这里你可以继续像

那样
  

var selecteds = [];

     

myrows.find(“select option:selected”)。each(function(){   selecteds.push($(本)的.text()); });

希望我说得对,如果没有,请回复我

编辑:

回答你的评论,我希望我知道你想让每个列表项目保持说cbxName,ddlVal和radioVal所以你可以像这样做一个“类”

function myType(cbxName, ddlVal , radioVal ){
    this.cbxName= cbxName;
    this.ddlVal = ddlVal ;
    this.radioVal = radioVal ;
};

var x = new myType(2, 3, 4);

然后你像这样迭代行:

  

myrows.each(function(index,element){

var r = $(this);
var cbxName = r.find("input[type=checkbox]").attr("name");
//or whatever the name is
var ddlVal = r.find("select").text();
//i think that will get u the selected text, if not do it like above
var radioVal = r.find("radio selector").attr("ur-att");
selecteds.push(new myType(cbxName , ddlVal , radioVal ));
     

});