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



 gridview中能删数据,不能更新!这是怎么回事呢?


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


gridview中能删数据,不能更新!这是怎么回事呢?
发表于:2007-02-02 14:06:07 楼主
我在视图中拖了个gridview   然后设置了数据连接   并且设置了主键datekeynames   也设置了   就是不能更新   !谁能帮我下   谢谢

<asp:gridview   id= "gridview1 "   runat= "server "   allowpaging= "true "   allowsorting= "true "
                autogeneratecolumns= "false "   datakeynames= "id "   datasourceid= "sqldatasource1 "   cellpadding= "4 "   forecolor= "#333333 "   gridlines= "none ">
                <columns>
                        <asp:commandfield   showdeletebutton= "true "   showeditbutton= "true "   showselectbutton= "true "   />
                        <asp:boundfield   datafield= "id "   headertext= "id "   insertvisible= "false "   readonly= "true "
                                sortexpression= "id "   />
                        <asp:boundfield   datafield= "name "   headertext= "name "   sortexpression= "name "   />
                </columns>
                <footerstyle   backcolor= "#5d7b9d "   font-bold= "true "   forecolor= "white "   />
                <rowstyle   backcolor= "#f7f6f3 "   forecolor= "#333333 "   />
                <editrowstyle   backcolor= "#999999 "   />
                <selectedrowstyle   backcolor= "#e2ded6 "   font-bold= "true "   forecolor= "#333333 "   />
                <pagerstyle   backcolor= "#284775 "   forecolor= "white "   horizontalalign= "center "   />
                <headerstyle   backcolor= "#5d7b9d "   font-bold= "true "   forecolor= "white "   />
                <alternatingrowstyle   backcolor= "white "   forecolor= "#284775 "   />
        </asp:gridview>
        <asp:sqldatasource   id= "sqldatasource1 "   runat= "server "   connectionstring= " <%$   connectionstrings:oildbconnectionstring3   %> "
                deletecommand= "delete   from   [yt]   where   [id]   =   @original_id "   insertcommand= "insert   into   [yt]   ([name])   values   (@name) "
                selectcommand= "select   [id],   [name]   from   [yt] "   updatecommand= "update   [yt]   set   [name]   =   @name   where   [id]   =   @original_id "   onselecting= "sqldatasource1_selecting "   oldvaluesparameterformatstring= "original_{0} ">
                <deleteparameters>
                        <asp:parameter   name= "original_id "   type= "int64 "   />
                </deleteparameters>
                <updateparameters>
                        <asp:parameter   name= "name "   type= "string "   />
                        <asp:parameter   name= "original_id "   type= "int64 "   />
                </updateparameters>
                <insertparameters>
                        <asp:parameter   name= "name "   type= "string "   />
                </insertparameters>
        </asp:sqldatasource>
发表于:2007-02-02 14:16:531楼 得分:0
在等。。别沉了
发表于:2007-02-02 14:25:002楼 得分:0
把后面的cs代码也发出来看看!
发表于:2007-02-02 14:28:453楼 得分:0
没有呀
发表于:2007-02-02 14:29:294楼 得分:0
我是直接拖的控件并且   用了   content内容模版
发表于:2007-02-02 14:36:095楼 得分:0
要代码的啊。不然怎么更新数据啊。
发表于:2007-02-02 14:37:316楼 得分:0
哦~   那你能帮我看下怎么写吗?
发表于:2007-02-02 14:37:327楼 得分:0
ispostback==false
发表于:2007-02-02 14:40:438楼 得分:0
protected   void   gridview1_rowupdating(object   sender,   gridviewupdateeventargs   e)
        {//更新                      
                int   i   =   int.parse(gridview1.datakeys[e.rowindex].value.tostring());
                string   title   =   ((textbox)gridview1.rows[e.rowindex].cells[1].controls[0]).text;
                string   subtitle   =   ((textbox)gridview1.rows[e.rowindex].cells[2].controls[0]).text;
                string   source   =   ((textbox)gridview1.rows[e.rowindex].cells[3].controls[0]).text;
                string   pubdate   =   ((textbox)gridview1.rows[e.rowindex].cells[4].controls[0]).text;
                string   implementdate   =   ((textbox)gridview1.rows[e.rowindex].cells[5].controls[0]).text;
                string   statutestate   =   ((textbox)gridview1.rows[e.rowindex].cells[6].controls[0]).text;
                string   typetitle   =   ((textbox)gridview1.rows[e.rowindex].cells[7].controls[0]).text;
                string   content   =   ((textbox)gridview1.rows[e.rowindex].cells[8].controls[0]).text;
                infos.update(title,   subtitle,   source,   pubdate,   implementdate,   statutestate,   typetitle,   content,   i);
                gridview1.editindex   =   -1;
                gridview1.datasource   =   infos.selectone(i);
                gridview1.databind();
        }
基本和上面很类似了
发表于:2007-02-02 14:44:239楼 得分:0
哦   谢谢你   我试下
发表于:2007-02-02 14:53:3410楼 得分:0
忘了。   。。   infos   是自己定义的一个对象。后面的方法selectont()   是一个跟新的sql语句执行方法。你自己换一下就成。
发表于:2007-02-03 16:29:0511楼 得分:0
还是有点不明白呢
发表于:2007-02-03 17:39:5812楼 得分:0
谁能在帮我解答下阿.谢谢了


快速检索

最新资讯
热门点击