简体   繁体   中英

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:

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

This is the code behind in my RowDataBound if it helps

    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

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

To

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

That did it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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