有条件地在网格视图行上设置按钮

本文关键字:设置 按钮 视图 网格 有条件 | 更新日期: 2023-09-27 18:31:51

>我的网格视图上有一个按钮:

<asp:Button ID="lnk_ship" runat="server" CssClass="btn-mini" Text="Ship Software" />

我正在将我的网格视图从SQL加载到一个类,然后是一个DataBind()事件,

protected void FilterResults(object sender, EventArgs e)
        {
            var shipments = new List<SoftShipments>();
            DateTime dt1 = Convert.ToDateTime(Textbox1.Text);
            DateTime dt2 = Convert.ToDateTime(Textbox2.Text);
            string cvt1 = "'" + dt1.Year.ToString() + "-" + dt1.Month.ToString() + "-" + dt1.Day.ToString() + "'";
            string cvt2 = "'" + dt2.Year.ToString() + "-" + dt2.Month.ToString() + "-" + dt2.Day.ToString() + "'";
            string qry = null;
            if (Showshipped.Checked)
            {
                qry = "select * from sft_Ship where sft_Entry_Dt between " + cvt1 + " and " + cvt2;
            }
            else {
                qry = "select * from sft_Ship where sft_Entry_Dt between " + cvt1 + " and " + cvt2 + " and sft_shipped = 'No'";
            }
            SqlConnection conn = new SqlConnection(Sitecore.Configuration.Settings.GetConnectionString("softship"));
            conn.Open();
            SqlCommand cmd = new SqlCommand(qry, conn);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                shipments.Add(new SoftShipments() { index = (int) dr["id"], softtitle = dr["sft_SoftTitle"].ToString(), 
                    productID = dr["sft_ProductID"].ToString(), ver = dr["sft_Version"].ToString(), 
                    custnam = dr["sft_CustName"].ToString(), title = dr["sft_Title"].ToString(), 
                    comp = dr["sft_Company"].ToString(), shipAddr = dr["sft_ShipAddress"].ToString(),
                    dept = dr["sft_Dept"].ToString(), city = dr["sft_City"].ToString(), state = dr["sft_State"]
                    .ToString(), postalCd = dr["sft_PostalCd"].ToString(), country = dr["sft_Country"].ToString(),
                    email = dr["sft_Email"].ToString(), entry_date = dr["sft_Entry_Dt"].ToString(), 
                    ship_date = dr["sft_Ship_Dt"].ToString(), shipped = dr["sft_Shipped"].ToString()
                    });
            }

            gdv_Ship.DataSource = shipments;
            gdv_Ship.DataBind();
            conn.Close();
        }

我想加载带有按钮的网格视图,如果值"已发货 = '否',或者如果'是'不可见......只是不太确定在哪里添加此代码?任何协助将不胜感激。

问候

有条件地在网格视图行上设置按钮

您可以订阅网格的databound事件,然后使用FindControl("controlName")显示/隐藏模板中的按钮