简体   繁体   English

处理时更改gridview行的背景颜色

[英]Change background color of gridview row while processing

What I need to do is to highlight each row when it is processing to show the process progress, the gridview may contain almost one thousands of row. 我需要做的是在处理过程中突出显示每一行以显示过程进度,gridview可能包含近一千行。 below is the code I have written but which doesn't work. 以下是我编写的代码,但是不起作用。 Please can someone help me. 请有人帮我。

< <

asp:GridView ID="gdview1" runat="server" BackColor="White"
                BorderColor="#DEDFDE" BorderStyle="Solid" BorderWidth="1px" CellPadding="4"
                ForeColor="Black" GridLines="Vertical" Font-Names="Calibri"
                Font-Size="Small" AutoGenerateColumns="False"
                OnRowDataBound="gdview1_RowDataBound"
                OnSelectedIndexChanged="gdview1_SelectedIndexChanged">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:CheckBox ID="chkBxHeader" OnCheckedChanged="chkSelect_CheckedChanged" AutoPostBack="true" runat="server" />
                        </HeaderTemplate>
                        <EditItemTemplate>
                            <asp:CheckBox ID="chkNUM" runat="server" />
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="chkNUM" runat="server" DataField="ColNUM" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Row#">
                        <ItemTemplate>
                            <%# Container.DataItemIndex + 1 %>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:BoundField DataField="ColNUM" HeaderText="Contract #" />
                    <asp:BoundField DataField="Col1" HeaderText="Suffix" />
                    <asp:BoundField DataField="Col2" HeaderText="First Name" />
                    <asp:BoundField DataField="Col3" HeaderText="Last Name" />
                    <asp:BoundField DataField="Col4" HeaderText="Street" />
                    <asp:BoundField DataField="Col5" HeaderText="City" />
                    <asp:BoundField DataField="Col6" HeaderText="Zip" />

                </Columns>
                <FooterStyle BackColor="#CCCC99" />
                <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
                <RowStyle BackColor="#F7F7DE" />
                <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#FBFBF2" />
                <SortedAscendingHeaderStyle BackColor="#848384" />
                <SortedDescendingCellStyle BackColor="#EAEAD3" />
                <SortedDescendingHeaderStyle BackColor="#575357" />

            </asp:GridView>




 namespace WebApplication1
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {

            }

            protected void butChargeCreditCards_Click(object sender, EventArgs e)
            {

                DataTable tblContrts = (DataTable) Session["tblContrts"];

                foreach (GridViewRow row in gdview1.Rows)
                {

                    CheckBox chkbx = (CheckBox) row.FindControl("chkNUM");

                    if (chkbx != null && chkbx.Checked)
                    {

                        gdview1_SelectedIndexChanged(row,e);



                        string SS = chkbx.Text.ToString();



                        string strResults = method1;



                    }


                }

            }


            protected void gdview1_SelectedIndexChanged(object sender, EventArgs e)
            {

                foreach (GridViewRow row in gdview1.Rows)
                {
                    if (row.RowIndex == gdview1.SelectedIndex)
                    {
                        row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
                    }
                    else
                    {
                        row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
                    }
                }
            }

        }
    }

Have you tried it by using the "OnRowDataBound" or "OnRowCreated" Event of the Grid and write the color-highliting in code behind? 您是否尝试过使用Grid的“ OnRowDataBound”或“ OnRowCreated”事件并在后面的代码中编写突出显示颜色的内容?

Something like this? 像这样吗
http://www.java2s.com/Code/ASP/ADO.net-Database/UsingtheRowCreatedEventtoprogrammaticallychangethestyle.htm http://www.java2s.com/Code/ASP/ADO.net-Database/使用RowCreated事件以编程方式更改style.htm

But maybe you have a problem because the loading would be too fast to really notice? 但是也许您有一个问题,因为加载太快而无法真正注意到?

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

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