您的位置:程序门 -> .net技术 -> asp.net



如何让 gridview 运行完自定义的事件后运行默认的事件


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何让 gridview 运行完自定义的事件后运行默认的事件[已结贴,结贴人:guostong]
发表于:2007-08-20 12:51:20 楼主
一个   gridview   有   “edit”按钮,可以编辑数据,
我想实现一个点击一行任何地方时就选中当前行的功能,

添加了如下代码:
        protected   override   void   oninit(eventargs   e)
        {
                base.oninit(e);
                initializecomponent();
        }
        private   void   initializecomponent()
        {
                gv_master.rowcommand   +=   new   gridviewcommandeventhandler(gv_master_rowcommand);
        }

        protected   void   gv_master_rowdatabound(object   sender,   gridviewroweventargs   e)
        {
                //   set   single_click   event   to   every   column
                if   (e.row.rowtype   ==   datacontrolrowtype.datarow)
                {
                        //   get   the   linkbutton   control   in   the   first   cell
                        linkbutton   singleclickbutton   =   (linkbutton)e.row.cells[0].controls[0];
                        //   get   the   javascript   which   is   assigned   to   this   linkbutton
                        string   jssingle   =   clientscript.getpostbackclienthyperlink(singleclickbutton,   " ");

                        //   add   events   to   each   editable   cell
                        for   (int   columnindex   =   m_ifirstcolumn;   columnindex   <   e.row.cells.count;   columnindex++)
                        {
                                //   add   the   column   index   as   the   event   argument   parameter
                                string   js   =   jssingle.insert(jssingle.length   -   2,   columnindex.tostring());
                                //   add   this   javascript   to   the   onclick   attribute   of   the   cell
                                e.row.cells[columnindex].attributes[ "onclick "]   =   js;
                                //   add   a   cursor   style   to   the   cells
                                e.row.cells[columnindex].attributes[ "style "]   +=   "cursor:pointer;cursor:hand; ";
                        }
                }
        }

        #region   render   override

        //   register   the   dynamically   created   client   scripts
        protected   override   void   render(htmltextwriter   writer)
        {
                //   the   client   events   for   gridview1   were   created   in   gridview1_rowdatabound
                foreach   (gridviewrow   r   in   gv_master.rows)
                {
                        if   (r.rowtype   ==   datacontrolrowtype.datarow)
                        {
                                for   (int   columnindex   =   m_ifirstcolumn;   columnindex   <   r.cells.count;   columnindex++)
                                {
                                        page.clientscript.registerforeventvalidation(r.uniqueid   +   "$ctl00 ",   columnindex.tostring());
                                }
                        }
                }

                base.render(writer);
        }

        #endregion

        protected   void   gv_master_rowcommand(object   sender,   gridviewcommandeventargs   e)
        {
                gridview   gridview   =   (gridview)sender;
                int   rowindex   =   int.parse(e.commandargument.tostring());

                switch   (e.commandname)
                {
                        case   ( "single_click "):
                                gv_master.selectedindex   =   rowindex;
                                break;
                        default:
                                break;

                }
        }

选中的功能实现了,但是“编辑”按钮不起作用了。请赐教


快速检索

最新资讯
热门点击