双击GridView查看详情

效果如下:

     protected void gvEquData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //鼠标经过改变样式
                e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='RosyBrown'");
                e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");

                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                string id = gvEquData.DataKeys[e.Row.RowIndex].Value == null ? string.Empty : gvEquData.DataKeys[e.Row.RowIndex].Value.ToString();
                string url = "?id=" + id;
                e.Row.Attributes.Add("ondblclick", "showDetailInfo('" + url + "');return false;"); //添加双击事件
            }
        }
  public partial class EquStatusDetail : System.Web.UI.Page
    {
        int rowFields = 3;//每一行显示的字段数;
        static Hashtable resources = EquStatusSearch.resources;
        Dictionary<String, String> fieldNameList = EquStatusSearch.fieldNameList;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string id = Request.QueryString["id"];//主键
                GetDetailInfo(id);
            }
        }

        public void GetDetailInfo(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                Image img = new Image();
                img.CssClass = "bgNull";
                img.ImageUrl = Server.MapPath("~/img/null.jpg");
                Panel1.Controls.Add(img);
                return;
            }
            DataRow dr = EquSearchBll.equBll.GetDetailEquInfoById(id);
            if (dr == null)
            {
                Image img = new Image();
                img.CssClass = "bgNull";
                img.ImageUrl = Server.MapPath("~/img/null.jpg");
                Panel1.Controls.Add(img);
            }
            if (dr != null)
            {
                if (string.IsNullOrEmpty(QuarrysClass.All))
                {
                    return;
                }

                string checkFlag = QuarrysClass.CheckFlag;
                string[] fields = QuarrysClass.All.Split(',');
                if (fields == null)
                {
                    return;
                }
            
                Table tb1 = new Table();
                tb1.CssClass = "usertableborder";
                tb1.Style.Add(HtmlTextWriterStyle.TextAlign, "left");
                tb1.Style.Add(HtmlTextWriterStyle.Width, "100%");
                int index = 0;
                TableRow tr = null;

                foreach (string f in fields)
                {
                    TableCell tc = new TableCell();
                    tc.Width = 150;
                    tc.CssClass = "usertablerow2";
                    TableCell tc1 = new TableCell();
                    tc1.CssClass = "usertablerow1";
                    tc1.Width = 120;

                    if (index % rowFields == 0)
                    {
                        tr = new TableRow();
                    }
                    if (checkFlag.ToLower().IndexOf("@" + f + "@") != -1)
                    {
                        tc.Text = resources[f] == null ? string.Empty : resources[f].ToString();
                        string strChecked = dr[f] == null ? string.Empty : dr[f].ToString();
                        CheckBox cbox = new CheckBox();
                        cbox.Enabled = false;
                        if (Convert.ToInt32(QuarrysClass.DataType) == (int)EnumDataType.ACCESS)
                        {
                            if (strChecked.ToLower() == "false")
                            {
                                cbox.Checked = false;
                            }
                            else
                            {
                                cbox.Checked = true;
                            }
                        }
                        else
                        {
                            if (strChecked == "1")
                            {
                                cbox.Checked = true;
                            }
                            else
                            {
                                cbox.Checked = false;
                            }
                        }
                        tc1.Controls.Add(cbox);
                        tr.Cells.Add(tc);
                        tr.Cells.Add(tc1);
                    }
                    else
                    {   
                        tc.Text = resources[f] == null ? string.Empty : resources[f].ToString();
                        if(QuarrysClass.Converts.ToLower().Contains(f))
                        {
                            tc1.Text=CommonClass.ConvertDateTime(dr[f]);
                        }
                        else
                        {
                        tc1.Text = dr[f] == null ? string.Empty : dr[f].ToString();
                        }
                        tr.Cells.Add(tc);
                        tr.Cells.Add(tc1);
                    }
                    if (index % rowFields == 0)
                    {
                        tb1.Rows.Add(tr);
                    }
                    index++;
                }
                Panel1.Controls.Add(tb1);
            }
        }
    }


原文地址:https://www.cnblogs.com/james1207/p/3299641.html