20151224001 GridView 多按钮的各种使用方法

<asp:GridView ID="GridView1"
                runat="server" AllowPaging="True" AutoGenerateColumns="False"
                BackColor="#78C7EB" BorderColor="#78C7EB" BorderWidth="1px"
                CellPadding="3" CellSpacing="2" DataKeyNames="ID"
                Height="50px" Width="810px" style="left: 3px; top: 3px"
                OnPageIndexChanging="GridView1_PageIndexChanging"
                OnRowDataBound="GridView1_RowDataBound"
                Font-Size="Large" PageSize="5"
                    onselectedindexchanged="GridView1_SelectedIndexChanged"
                    onrowcommand="GridView1_RowCommand" onrowdeleting="GridView1_RowDeleting">
                <FooterStyle BackColor="#F7DFB5" ForeColor="#46434F" Font-Bold="False" />
                <RowStyle BackColor="#EDF6FA" ForeColor="#46434F" />
                <Columns>
               
                   
                    <asp:CommandField HeaderText="查看" ShowSelectButton="True" SelectText="查看" >
                        <HeaderStyle BackColor="#4B9D1A" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="38px" ForeColor="#003300" />
                    </asp:CommandField>

<asp:CommandField DeleteText="变更" HeaderText="变更" ShowDeleteButton="True">
                        <HeaderStyle BackColor="#4B9D1A" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="38px" ForeColor="#CA0ED3" />
                    </asp:CommandField>

<asp:ButtonField ButtonType="Button" Text="取消" HeaderText="取消"
                        CommandName="b_cancel">
                        <ControlStyle ForeColor="#800010" />
                        <HeaderStyle BackColor="#4B9D1A" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="38px" ForeColor="#CA0ED3" />
                    </asp:ButtonField>
               
                   
                    <asp:BoundField DataField="ID" HeaderText="编号" ReadOnly="True"
                        SortExpression="ID" >
                        <HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="28px" />
                    </asp:BoundField>

<asp:BoundField DataField="M_Title" HeaderText="会议主题" SortExpression="M_Title" >
                        <HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="160px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="M_Room" HeaderText="会议室" SortExpression="M_Room" >
                        <HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="60px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="M_Chairman" HeaderText="主持人"
                        SortExpression="M_Chairman" >
                        <HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="60px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="M_S_Time" HeaderText="开始时间"
                        SortExpression="M_S_Time" >
                        <HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="80px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="M_E_Time" HeaderText="结束时间"
                        SortExpression="M_E_Time" >
                        <HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="80px" />
                    </asp:BoundField>
                     <asp:BoundField DataField="M_Person" HeaderText="与会人"
                        SortExpression="M_Person" >
                        <HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="100px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="M_Operator" HeaderText="预约人"
                        SortExpression="M_Operator" >
                        <HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="60px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="M_Operator_Date" HeaderText="预约时间"
                        SortExpression="M_Operator_Date" >
                        <HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
                            BorderWidth="1px" Font-Size="Medium" />
                        <ItemStyle HorizontalAlign="Center" BorderWidth="1px"
                            Font-Size="Small" BorderColor="#34A7DC" Width="80px" />
                    </asp:BoundField>
                   
                  
                   
                </Columns>
                <PagerStyle ForeColor="#EDF6FA" HorizontalAlign="Center" Font-Bold="True"
                      Font-Italic="False" Font-Names="Arial Black" Font-Overline="False"
                      Font-Size="Medium" Font-Underline="False" Height="28px" />
                <SelectedRowStyle BackColor="#4B9D1A" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#EDF6FA" Font-Bold="True" ForeColor="White"
                      Font-Size="Small" Height="38px" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>

******************************************************************************************************

protected void databind()
    {
        P_ht.H_data P_data = new P_ht.H_data();

P_data.sql_text1 = Str_sql;
        P_data.select_tables();
        DataSet1 = P_data.DataSet8;
        Session["session_table"] = P_data.DataSet8;
        this.GridView1.DataSource = DataSet1;
        this.GridView1.DataBind();
    }

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        this.DataSet2 = new System.Data.DataSet();
        this.DataSet2 = (DataSet)Session["session_table"];
        this.GridView1.DataSource = this.DataSet2;
        this.GridView1.DataBind();
    }

//
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int i;
        //执行循环,保证每条数据都可以更新
        for (i = -1; i < GridView1.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor=‘#bcbf56‘");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }

if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Button b = e.Row.Cells[0].Controls[0] as Button;
            Button b = e.Row.Cells[2].Controls[0] as Button;
            b.Attributes.Add("onclick", "if(confirm(‘你确认要取消选中的会议预约吗?‘)){ __doPostBack(‘GridView1‘,‘$" + e.Row.RowIndex + "‘)}else{return false;}");
        }
    }

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //GridView g = (e.CommandSource as GridView);
        ////Label1.Text = "你选择的行 ID = " + g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value;
        //if (Convert.ToInt32(g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value) != null)
        //{
        //    if (Convert.ToInt32(g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString()) > 0)
        //    {
        //        ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
        //        scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: " + g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString() + "  ‘);", true);
        //    }
        //}

// 在RowCommand事件中通过CommandName来区分点击了哪个Button
        GridView g = (e.CommandSource as GridView);
        if (e.CommandName == "b_cancel")
        {
            ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
            scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: " + g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString() + "  ‘);", true);
        }
    }

//
    static string str_ca = "";
    protected void btn_i_date1_Click(object sender, ImageClickEventArgs e)
    {
        LayerCC.Visible = !LayerCC.Visible;
        str_ca = "1";
    }
    protected void btn_i_date2_Click(object sender, ImageClickEventArgs e)
    {
        LayerCC.Visible = !LayerCC.Visible;
        str_ca = "2";
    }

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        if (str_ca == "1")
        {
            txt_date1.Text = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
            LayerCC.Visible = false;
        }

if (str_ca == "2")
        {
            txt_date2.Text = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
            LayerCC.Visible = false;
        }
    }

protected void btn_i_confirm_Click(object sender, ImageClickEventArgs e)
    {
        //
        string str_room = "";
        if (Session["meeting_room"] == null)
        {
            str_room = "";
        }
        else
        {
            str_room = Session["meeting_room"].ToString();
        }

//
        dt1 = System.Convert.ToDateTime(txt_date1.Text.Trim() + " 00:00:00 ");
        dt2 = System.Convert.ToDateTime(txt_date2.Text.Trim() + " 23:59:59 ");

//
        databind();

}

//
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;

// Display the company name from the selected row.
        // In this example, the third column (index 2) contains
        // the company name.

//Message.Text = "You selected " + row.Cells[2].Text + ". ";

ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
        scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: " +  row.Cells[3].Text + " 查看 ‘);", true);
    }

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //string str_a = e.RowIndex.ToString();
        //string str_a = e.Keys.ToString();
        ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
        scriptManager.RegisterStartupScript(typeof(string), "", "alert(‘提示: " + GridView1.Rows[e.RowIndex].Cells[3].Text.ToString().Trim() + " 编辑 ‘);", true);
    }
}

时间: 2024-08-07 00:17:12

20151224001 GridView 多按钮的各种使用方法的相关文章

gridview获取当前行索引的方法

在用GridView控件时,我们经常会碰到获取当前行的索引,通过索引进行许多操作.例如,可以获得当前行某一个控件元素:设置某一元素的值等等. 下面结合实例介绍几种获得GridView当前行索引值的方法. 实例: ① 目的:获取GridView中RowCommand的当前索引行. ② 前台页面:在GridView中添加一模版列,里面添加一个LinkButton控件. 代码: <asp:TemplateField HeaderText="操作"> <ItemTemplat

代码添加一个按钮及监听方法

有时候无法从控件中拖拽一个按钮到storyboard,必须用编写代码方式添加按钮: 1 - (void)viewDidLoad 2 { 3 [super viewDidLoad]; 4 // Do any additional setup after loading the view, typically from a nib. 5 //计算出展示表情区域的宽和 展示区距顶部的高度+10个偏移量 6 //添加按钮 9 //创建button 10 addBtn = [[UIButton alloc

安卓activity捕获返回按钮关闭应用的方法

安卓activity捕获返回按钮关闭应用的方法 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { //按下键盘上返回按钮 if(keyCode == KeyEvent.KEYCODE_BACK){ new AlertDialog.Builder(this) .setIcon(R.drawable.alert_dialog_icon) .setTitle("提示") .setMessage("是否

Cocos Creator开发中的按钮节点的事件处理方法

Cocos Creator开发中的按钮节点的事件处理方法 Cocos Creator基于Cocos2d-x(C++方案),提出全新的编程理念.Cocos Creator是以内容创作为核心的游戏开发工具,在Cocos2d-x基础上实现了彻底脚本化(可以使用Javascript.Typescript或者Coffeescript).组件化和数据驱动等特点.但是,在事件处理机制上并不显得简单,至少是新手初学阶段如此.下面我们通过场景制作中按钮组件的事件处理机制来说明这个问题. 试验目的 通过为按钮组件设

win8.1系统开始屏幕添加锁屏按钮的详细的方法

我们在win8电脑的使用中,有小伙伴在使用中有锁屏的功能的方法,这对我们的操作时很有帮助的,今天看到有小伙伴在使用中在开始菜单中出现了没有锁屏的情况,这样的情况我们怎么解决呢,今天小编就来跟大家分享一下win8.1系统开始屏幕添加锁屏按钮的详细的方法,一起跟小编来看看详细的方法吧. 具体的方法和详细的步骤如下: 1.首先来到桌面,右键点左下角图标打开菜单,选择"控制面板": 2.来到"控制面板"后,在"查看方式"为"类别"的情

gridview添加按钮及其按钮操作

先晒出两篇在网路上找到的关于gridview的一些操作 http://www.cnblogs.com/xiaobaigang/articles/824011.html http://www.blogjava.net/liuyz2006/articles/378151.html 接下来,在gridview如何添加按钮,并书写按钮的触发事件 1.点击gridview右边那个小三角,添加新列,选择button,记得修改属性,不是link 2.设置完成后,进入gridview的列编辑界面,点击将此字段转

android 之 ListView 里面嵌套 GridView 遇到的问题及其解决方法。

我们直接入主题.所有问题例子请参照下图 1,怎样使图片具有点击事件? 答: 解决方法: 在你的BaseAdapter里面不要设置下面这三个东西,然后再设置GridView的onItemClick. gridView.setClickable(false); gridView.setPressed(false); gridView.setEnabled(false); 2,为什么我在已经处理了listView点击事件阻断的情况下,同时图片具有点击事件,此时再点击和图片同高度的空白处,却无法执行li

Android 防止按钮连续点击的方法(Button,ImageButton等)

防止按钮连续点击 共通方法: public class Utils { private static long lastClickTime; public static boolean isFastDoubleClick() { long time = System.currentTimeMillis(); if ( time - lastClickTime < 500) { return true; } lastClickTime = time; return false; } } 按钮点击时

ListView 里面嵌套 GridView 遇到的问题及其解决方法。

我们直接入主题.所有问题例子请参照下图 1,怎样使图片具有点击事件? 答: 解决方法: 在你的BaseAdapter里面不要设置下面这三个东西,然后再设置GridView的onItemClick. gridView.setClickable(false); gridView.setPressed(false); gridView.setEnabled(false); 2,为什么我在已经处理了listView点击事件阻断的情况下,同时图片具有点击事件,此时再点击和图片同高度的空白处,却无法执行li