Gridview backgroundcolor属性无法保留在模板字段中的单击链接按钮上. [英] Gridview backgroundcolor property not retaining on clicking link button in template field.

查看:213
本文介绍了Gridview backgroundcolor属性无法保留在模板字段中的单击链接按钮上.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨社区,

我在ASP .NET Web窗体上有 GridView .该GridView绑定到 SQLDataSource .所有列都是 TemplateField . GridView在 UpdatePanel 内部.列之一是 DropDownList ,此DropDownList的HTML标记如下:

Hi Community,

I have GridView on an ASP .NET Web Form. This GridView is bound to an SQLDataSource. All columns are TemplateField. The GridView is inside an UpdatePanel. One of the Columns is DropDownList the HTML Markup for this DropDownList is as follows:

<asp:DropDownList ID="DropDownList1" onchange="buildDropDown(this)" runat="server" Text='<%# Bind("[r_cal_M]") %>'>
    <asp:ListItem></asp:ListItem>
    <asp:ListItem>2016-09</asp:ListItem>
    <asp:ListItem>2016-10</asp:ListItem>
    <asp:ListItem>2016-11</asp:ListItem>
    <asp:ListItem>2016-12</asp:ListItem>
</asp:DropDownList>



buildDropDown()函数的代码为:



The Code for buildDropDown() Function is:

function buildDropDown(obj) {
    var status = obj.options[obj.selectedIndex].value;
    var row = obj.parentNode.parentNode;
    var rowIndex = row.rowIndex - 1;

    var ddlReason = row.cells[1].getElementsByTagName('SELECT')[0];

    switch (status) {
        case "":
            row.style.backgroundColor = "rgb(255, 255, 255)";
            row.style.color = "rgb(0, 0, 0)";
            break;
        case "2016-09":
            row.style.backgroundColor = "rgb(198, 239, 206)";
            row.style.color = "rgb(0, 97, 0)";
            break;
        case "2016-10":
            row.style.backgroundColor = "rgb(1255, 199, 206)";
            row.style.color = "rgb(156, 0, 6)";
            break;
        case "2016-11":
            row.style.backgroundColor = "rgb(255, 235, 156)";
            row.style.color = "rgb(156, 101, 0)";
            break;
        case "2016-12":
            row.style.backgroundColor = "rgb(255, 255, 255)";
            row.style.color = "rgb(0, 0, 0)";
            break;
    }
}



该应用程序运行正常,但是当我单击GridView中的更新"按钮时,该行的颜色变回原始颜色.

我该如何解决?

我尝试过的事情:

向更新按钮的OnClientClick添加了JavaScript函数(用于使用颜色编码方案之一进行测试):



The application is working fine but when I click the update button in the GridView the color of the row changes back to original.

How can I fix this?

What I have tried:

Added a JavaScript Function to the OnClientClick of the Update Button (for testing with one of the Color Coding Schemes):

function Validate(lnkUpdate) {

    var row = lnkUpdate.parentNode.parentNode; 


    row.style.backgroundColor = "rgb(255, 235, 156)";
    row.style.color = "rgb(156, 101, 0)";


    return true;
}


颜色仍然变回原始颜色(带有黑色ForeColor的白色背景)


Still the color changes back to original (White background with Black ForeColor)

推荐答案

我认为这是发生在页面上的原因.您应该处理RowDataBound事件.在该事件内部,检查数据并根据需要为每行分配背景色.
I think it is happening because the page posts back. You should handle the RowDataBound event. Inside that event check the data and assign background color to each row as required.


这篇关于Gridview backgroundcolor属性无法保留在模板字段中的单击链接按钮上.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆