• GridView用编辑或详细链接提取选中行数据 Alec


    方法一:
    1、在GridView中添加一个TemplateField字段,把他的ShowHeader改为False。(或在HTML代码中加上  【DataKeyNames="newsId"】这一句,其中【newsId】为GridView绑定的数据库的主码。)
    2、在GridView的编辑模板中添加一个LinkButton,修改CommandName=Edit,CausesValidation=False,Text="编辑"。
    3、在GridView的【RowEditing】事件中加上如下代码:
        Session["id"] = Convert.ToInt32(gvNews.DataKeys[e.NewEditIndex].Value);     Response.Redirect   ("ModifyNews.aspx");
    4、在接受选中行数据的页面(即【ModifyNews.aspx】)中,添加如下代码:
       int id = Convert.ToInt32(Session["id"]);
       var news= XLzt.Business.NewNoticeManage.News.GetNewById(id);
       this.txtNewsTtitle.Text= news.title;
       this.txtModifyTimes.Value= news.publishTime.Value.ToShortDateString();
       ……
    方法二:
    1、在GridView中添加一个HyperLinkField可用字段,修改Text属性为“详细”或“编辑”
    2、修改DataNavigateUrlFields属性为GridView要绑定的数据库的主键
    3、修改DataNavigateUrlFormatString属性为要跳转的页面,并设置id值:
          ProductInformation.aspx?productInforId={0}(productInforId为数据库主键或Model层得主键映射)
    4、在详细或编辑页面的Page_Load()中增加如下代码:
     if (!IsPostBack)
                {
                    if (Request.QueryString["productInforId"] != null)
                    {
                        int productID = Convert.ToInt32(Request.QueryString["productInforId"].ToString());
                        var member = CRM.Business.Product.GetNewById(productID);
                        if (member != null)
                        {
                            this.lblModel.Text = member.model;
                            this.lblType.Text = member.type;
                            this.lblBrand.Text = member.brand;
                            this.lblInnerDiameter.Text = member.innerDiameter.ToString();
                            this.lblExternalDiameter.Text = member.externalDiameter.ToString();
                            this.lblHeight.Text = member.height.ToString();
                            this.lblLimitSpeed.Text = member.limitSpeed.ToString();
                            this.lblReferenceSpeed.Text = member.referenceSpeed.ToString();
                            this.imgResult.ImageUrl = member.image;                       
                        }
                    }
                }

  • 相关阅读:
    HDU2586 How far away?(tarjan的LCA)
    You Raise Me Up
    POJ2891 Strange Way to Express Integers(中国剩余定理)
    POJ2142 The Balance(扩展欧几里得)
    HDU 1166模仿大牛写的线段树
    NetWord Dinic
    HDU 1754 线段树裸题
    hdu1394 Minimum Inversion Number
    hdu2795 Billboard
    【完全版】线段树
  • 原文地址:https://www.cnblogs.com/yinluhui0229/p/2025467.html
Copyright © 2020-2023  润新知