Create a table header in the Gridview, click the cell pop-up dialog box, and change the cell background color.

Source: Internet
Author: User

Create a table header in the Gridview, click the cell pop-up dialog box, and change the cell background color.

Sort work ~

The complete code is on GitHub. Path:

Project Background: track an issue and record the daily status.

Requirements: 1. Click the date to change the status.

2. Add a button to disable issue.

3. layout requires that the date be placed after the tracking information

 

After receiving this short and competent requirement, I thought it was a bit confusing and I didn't have any sample images. The main requirement is a group of people who do not fully understand development. They are completely, completely, and completely ignorant !!! Miss the days of software companies ......

I thought about it, drew a sketch similar to the following, and wrote a Specification in detail according to the requirements. After the consistency is passed, I began to prepare for writing this function ....

Let's just look at the diagram and code ~

 

:

 

The front-end. aspx code is short and only one invisible ButtonField is bound for cell Click Event

Major background code snippets

Recreate the header in the event gvData_RowCreated.

 switch (e.Row.RowType)            {                   case DataControlRowType.Header:                    TableCellCollection tcHeader = e.Row.Cells;                    tcHeader.Clear();                    tcHeader.Add(new TableHeaderCell());                    tcHeader[0].Text = "xxxx";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[1].Text = "xxxx";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[2].Text = "xxxx";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[3].Text = "xxxx";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[4].Text = "xxxxx";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[5].Text = "xxxxx";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[6].Text = "xxxx.";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[7].Text = "xxxxx";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[8].Text = "xxxxx";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[9].Text = "xxxxx";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[10].Text = "Status";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[11].Text = "Remarks";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[12].Text = "Month";                    tcHeader.Add(new TableHeaderCell());                    tcHeader[13].Attributes.Add("colspan", "31");                    tcHeader[13].Text = "xxxx Data";                    break;            }

Click the Event code. First, you need to set the column from which you can click the pop-up box. Then, in the RowDataBound event, you can click and pop-up box.

  if (e.Row.RowType == DataControlRowType.DataRow)            {                LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];                string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "");                //add events to each editable cell                for (int columnIndex = _firstEditCellIndex; columnIndex < e.Row.Cells.Count; columnIndex++)                {                    //add the column index as the event argument parameter                    string js = _jsSingle.Insert(_jsSingle.Length - 2, columnIndex.ToString());                    e.Row.Cells[columnIndex].Attributes["onclick"] = js;                    e.Row.Cells[columnIndex].Attributes["style"] += "cursor:pointer;cursor:hand;";                    e.Row.Cells[columnIndex].Attributes.Add("onclick", "openWin('" + requestNo + "','" + month + "','" + date + "');");                                    }            }

Changing the cell background color is also in RowDataBound.

 if (date.Contains("P"))                        {                            date = date.TrimEnd('P');                            e.Row.Cells[columnIndex].BackColor = ColorTranslator.FromHtml("#525f6b");                        }                        if (date.Contains("Y"))                        {                            date = date.TrimEnd('Y');                            e.Row.Cells[columnIndex].BackColor = ColorTranslator.FromHtml("#fac970");                        }                        if (date.Contains("L"))                        {                            date = date.TrimEnd('L');                            e.Row.Cells[columnIndex].BackColor = ColorTranslator.FromHtml("#15a452");                        }                        if (date.Contains("R"))                        {                            date = date.TrimEnd('R');                            e.Row.Cells[columnIndex].BackColor = Color.Red;                        }                        if (date.Contains("B"))                        {                            date = date.TrimEnd('B');                            e.Row.Cells[columnIndex].BackColor = ColorTranslator.FromHtml("#004986");                        }                        e.Row.Cells[columnIndex].Text = date;

Set the Status column to click to close the column. The Code is as follows:

   string editJs = _jsSingle.Insert(_jsSingle.Length - 2, 11.ToString());   e.Row.Cells[11].Attributes["onclick"] = editJs;   e.Row.Cells[11].Attributes["style"] += "cursor:pointer;cursor:hand;";   if (e.Row.Cells[11].Text == "Ongoing")      e.Row.Cells[11].Text = "

The possible implementation method is not very good. Please advise more ~

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.