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



自定义数据源时,如何使用gridview 的功能按钮?


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


自定义数据源时,如何使用gridview 的功能按钮?[已结贴,结贴人:guostong]
发表于:2007-08-20 12:02:34 楼主
//   .aspx:

<asp:gridview   id= "gv_master "   runat= "server "   autogeneratecolumns= "false "
                        width= "291px "   datakeynames= "id ">
                        <columns>
                                <asp:boundfield   datafield= "id "   headertext= "id "   />
                                <asp:boundfield   datafield= "class "   headertext= "class "   />
                                <asp:boundfield   datafield= "name "   headertext= "name "   />
                                <asp:commandfield   showeditbutton= "true "     />
                        </columns>
                </asp:gridview>

//   .cs

        protected   void   page_load(object   sender,   eventargs   e)
        {
                if   (!ispostback)
                {
                        gv_master.datasource   =   dmglobal.dttestproduct();
                        gv_master.databind();
                }
        }

在表格中按   "edit "按钮后得到如下异常:
the   gridview   'gv_master '   fired   event   rowediting   which   wasn 't   handled.  
description:   an   unhandled   exception   occurred   during   the   EXECution   of   the   current   web   request.   please   review   the   stack   trace   for   more   information   about   the   error   and   where   it   originated   in   the   code.  

exception   details:   system.web.httpexception:   the   gridview   'gv_master '   fired   event   rowediting   which   wasn 't   handled.

source   error:  

an   unhandled   exception   was   generated   during   the   EXECution   of   the   current   web   request.   information   regarding   the   origin   and   location   of   the   exception   can   be   identified   using   the   exception   stack   trace   below.    

但如果使用指定一个   数据源   就没有问题,请赐教
发表于:2007-08-20 12:38:181楼 得分:10
rowediting
把这个事件加上就应该可以了
发表于:2007-08-20 12:48:282楼 得分:10
.aspx:
<asp:gridview   id= "gridview1 "   runat= "server "   onrowediting= "editing ">
   <columns>
     <asp:commandfield   showeditbutton= "true "   />
   </columns>
</asp:gridview>

.cs:
protected   void   editing(object   sender,   gridviewediteventargs   e)
{
  gridview1.editindex   =   e.neweditindex;

}

其他事件,如:delete,cancel,update也是相似的,如果还有什么不明白,查一下msdn


快速检索

最新资讯
热门点击