GridView中动态设置CommandField是否可用或可见的小例子_实用技巧

复制代码 代码如下:

 protected void gvMaterial_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;

            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[1].Text = (gvMaterial.PageIndex * gvMaterial.PageSize + e.Row.RowIndex + 1).ToString();
                string price;
                try //让编辑功能在特定条件下可以用
                {
                     price = ((TextBox)e.Row.Cells[4].Controls[0]).Text;//点编辑的时候用
                }
                catch
                {
                     price = e.Row.Cells[4].Text;    //出始时用
                }                         
                if (price == "" || price == " ")
                {
                    e.Row.Cells[7].Controls[0].Visible = false;
                }
                else
                {
                    e.Row.Cells[7].Controls[0].Visible = true;
                }
            }
        }
 

时间: 2024-09-12 08:36:43

GridView中动态设置CommandField是否可用或可见的小例子_实用技巧的相关文章

asp.net 合并GridView中某列相同信息的行(单元格)_实用技巧

                                        解决方法如下(写在公共模块里,定义为静态方法方便调用): 复制代码 代码如下: /// <summary> /// 合并GridView中某列相同信息的行(单元格) /// </summary> /// <param name="GridView1">GridView</param> /// <param name="cellNum"

asp.net中GridView控件遍历的小例子_实用技巧

复制代码 代码如下: int intCount = this.GridView1.Rows.Count; //总行数for (int i = 0; i < intCount; i++){  Label1.Text = ((HyperLink)GridView1.Rows[i].Cells[0].Controls[0]).Text.ToString().Trim(); } for (i = 0; i < GridViewID.Rows.Count; i++){   CheckBox chkVot

asp.net 编辑gridview的小例子_实用技巧

编辑gridview例子,完整代码如下. 复制代码 代码如下: protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)     {         GridView1.EditIndex = e.NewEditIndex;         BingGrid();     }     protected void GridView1_RowCancelingEdit(object sender, Gri

.net中使用xsl文件作为导航菜单的小例子_实用技巧

复制代码 代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="testweb.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww

VB.NET 中删除DataGridView中所选行的小例子_实用技巧

复制代码 代码如下: For Each r As DataGridViewRow In DataGridView1.SelectedRows    If Not r.IsNewRow Then        DataGridView1.Rows.Remove(r)    End IfNext 其实就是一个IsNewRow属性,判断是不是为新选中的行,如果不是,remove!

Asp.net中获取应用程序完整Url路径的小例子_实用技巧

复制代码 代码如下: /// <summary> /// Gets the absolute root /// </summary> public static Uri AbsoluteWebRoot {     get  www.jb51.net    {         var context = HttpContext.Current;         UriBuilder uri = new UriBuilder();         uri.Host = context.

关于ASP.NET中TreeView用法的一个小例子_实用技巧

复制代码 代码如下: using System;using System.Collections;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebContr

为GridView的行添加鼠标经过、点击事件的小例子_实用技巧

复制代码 代码如下:    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    {        e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#95B8FF'");        e.Row.Attributes.Ad

GridView使用CommandField删除列实现删除时提示确认框_实用技巧

GridView在使用CommandField删除时弹出提示框,在.net2005提供的GridView中我们可以直接添加一个CommandField删除列:<asp:CommandField ShowDeleteButton="True" />,完后在它的RowDeleting事件中完成删除.但在多半我们在做这种删除操作时都需要先让操作者再确认下,完后再进行删除,以避免误操作引起的误删除. 可以通过下面方法给GridView删除前加上个确认对话框. 首先,在GridVie