简体   繁体   English

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

[英]Radio Button Set As checked but not getting displayed as checked after postback Gridview JQuery

I have a JQuery Code that clones my grid, strips the rows and leaves the header fixed, this is the Code: 我有一个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);
    }

If I select a row in my grid by the first cell which is a radio button and I edit that row after the postback I highlight and have the radio button checked for the row I edited, this works if I don't have the JQuery above, but when I do the highlighting works and the radio buttons says its set to true but It is not displayed as such 如果我在第一个单元格旁边的网格中选择了一个行,该行是一个单选按钮,并且在突出显示回发后编辑了该行,并选中了单选按钮以检查编辑的行,那么如果我上面没有JQuery,则可以使用,但是当我执行突出显示工作并且单选按钮将其设置为true时,它不会显示为true

This is the code behind in my RowDataBound if it helps 这是我的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;
                }

        }
    }

Any help is very appreciated, thanks! 任何帮助都非常感谢,谢谢!

The Problem is that I was hiding the rest of the grid instead of removing it so I changed the JQuery line from 问题是我隐藏了网格的其余部分,而不是将其删除,因此我将JQuery行从

 $(gridHeader).find("tr:gt(0)").hide();

To

 $(gridHeader).find("tr:gt(0)").remove();

That did it! 做到了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM