簡體   English   中英

在回發Gridview JQuery后單選按鈕設置為選中狀態,但未顯示為選中狀態

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

我有一個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時,它不會顯示為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;
                }

        }
    }

任何幫助都非常感謝,謝謝!

問題是我隱藏了網格的其余部分,而不是將其刪除,因此我將JQuery行從

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

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

做到了!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM