单选按钮设置已选中但在回发Gridview JQuery后未显示为已选中

时间:2015-07-22 22:10:14

标签: javascript c# jquery asp.net gridview

我有一个克隆我的网格的JQuery代码,剥离行并保留标题,这就是代码:

function fixedHeader() {
        // Code to copy the gridview header with style
        var gridHeader = $('#<%=GridView1.ClientID%>').clone(true).attr('id','clonedGrid'); 
        //Code to remove all rows except the header row
        $(gridHeader).find("tr:gt(0)").hide();
        $('#<%=GridView1.ClientID%> tr th').each(function (i) {
            // Here Set Width of each th from gridview to new table th 
            $("th:nth-child(" + (i + 1) + ")", gridHeader).css('width', ($(this).width()).toString() + "px");
        });
        // Append Header to the div controlHead
        $("#controlHead").append(gridHeader);
        // Set its position to be fixed
        $('#controlHead').css('position', 'fixed');
        // Put it on top
        $('#controlHead').css('top', $('#<%=GridView1.ClientID%>').offset().top);
    }

如果我在网格中通过第一个单元格选择了一行,这是一个单选按钮,我在回发后编辑该行,我突出显示并检查了我编辑的行的单选按钮,如果我没有上面的JQuery,但当我做突出显示工作和单选按钮说它设置为true但它没有显示为

这是我的RowDataBound背后的代码,如果它有帮助

    private void rbCheckedandHighlight(GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // Retrive Row index
            string previousSelectedRow = ViewState["selectedIndex"].ToString();
            // Retrive Button Name
            string btnName = ViewState["ButtonName"].ToString();
            // See if its even or odd
            int indexType = (int)ViewState["oddOrEvenIndex"];
            // Response.Write(previousSelectedRow);

                // Get the radio button instance of that row we just extracted
                RadioButton radioBtnChecked = e.Row.FindControl("chkChoose") as RadioButton;
                // Get PK of the Row
                string oid = e.Row.Cells[11].Text;

                /**************************************************************
                * This logic is placed to make sure that if the user selected a
                * row before pressing insert it will not highlight that row  
                * while on insert mode, instead it will display the normal color  
                * it corresponds to that row. Then after the hittin cancel 
                * it will Highlight the row back again.
                ****************************************************************/
                if (oid == previousSelectedRow && btnName == "edit" || oid == previousSelectedRow && btnName == "insertCancel")
                {
                   radioBtnChecked.Checked = true;
                    e.Row.BackColor = System.Drawing.Color.FromArgb(155, 194, 126);
                }
                else if (oid == previousSelectedRow && btnName == "insert" && indexType == 0)
                {
                   radioBtnChecked.Checked = true;
                    e.Row.BackColor = System.Drawing.Color.FromArgb(227, 234, 235);
                }
                else if (oid == previousSelectedRow && btnName == "insert" && indexType == 1)
                {
                   radioBtnChecked.Checked = true;
                    e.Row.BackColor = System.Drawing.Color.White;
                }

        }
    }

非常感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

问题是我隐藏了网格的其余部分而不是删除它所以我从

更改了JQuery行
 $(gridHeader).find("tr:gt(0)").remove();

var test: Int

for i in raindays {
  if i <= 11 {
    test = et_raindays_lessthan_11
  }
  else if i > 11 {
    test = et_raindays_morethan_11
  }
  evap_transpiration.append(test)
}

那就做到了!