首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

GridView的更新按钮有关问题[分不够可以再给]

2011-12-24 
GridView的更新按钮问题[分不够可以再给]点击编辑后,我更新里面的内容然后点击更新,可是就是更新不了更新

GridView的更新按钮问题[分不够可以再给]
点击编辑后,我更新里面的内容
然后点击更新,可是就是更新不了

更新按钮的代码
protected   void   GVeditor_RowUpdated(object   sender,   GridViewUpdatedEventArgs   e)
        {
              try
                {
                        string   cj   =   ((TextBox)e.NewValues[5]).Text;//成绩
                        string   kccj   =   ((TextBox)e.NewValues[6]).Text;//考查成绩
                        string   xk   =   ((TextBox)e.NewValues[1]).Text;//学生ID
                        string   km   =   ((TextBox)e.NewValues[4]).Text;//科目

                        string   cmdtext   =   "update   成绩   set   成绩= ' "   +   cj   +   " ',考查成绩= ' "   +   kccj   +   " '   where   成绩.学生= ' "   +   xk   +   " '   and   成绩.科目   in   (select   ID   from   科目   where   科目.科目= ' "   +   km   +   " ') ";
                        SqlConnection   sqlconn   =   new   SqlConnection(sqllink.sqlconn());
                        sqlconn.Open();

                        SqlCommand   sqlcomm   =   new   SqlCommand(cmdtext,   sqlconn);
                        sqlcomm.ExecuteNonQuery();
                        sqlconn.Close();
                }
                catch   (Exception   ex)
                {
                        Response.Write(ex.Message);
                }
                this.GVeditor.DataSource   =   gvBind();
                this.GVeditor.DataBind();      
                GVeditor.EditIndex   =   -1;
}

////////////////////HTML代码
      <asp:GridView   ID= "GVeditor "   runat= "server "   Width= "100% "   Height= "72px "   AutoGenerateColumns= "False "   OnRowCancelingEdit= "GVeditor_RowCancelingEdit "   OnRowEditing= "GVeditor_RowEditing "   OnRowUpdating= "GVeditor_RowUpdating "   OnRowUpdated= "GVeditor_RowUpdated "   >
                                <Columns>
                                        <asp:BoundField   DataField= "学号 "   HeaderText= "学号 "   ReadOnly= "True "   />


                                        <asp:BoundField   DataField= "班级 "   HeaderText= "班级 "   ReadOnly= "True "   />
                                        <asp:BoundField   DataField= "姓名 "   HeaderText= "姓名 "   ReadOnly= "True "   />
                                        <asp:BoundField   DataField= "科目 "   HeaderText= "科目 "   ReadOnly= "True "   />
                                        <asp:TemplateField   HeaderText= "成绩 ">
                                                <EditItemTemplate>
                                                        <asp:TextBox   ID= "TextBox1 "   runat= "server "   Text= ' <%#Eval( "成绩 ")   %> '> </asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                        <asp:Label   ID= "Label3 "   runat= "server "   Text= ' <%#Eval( "成绩 ")   %> '> </asp:Label>
                                                </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField   HeaderText= "考查成绩 ">
                                                <EditItemTemplate>
                                                        <asp:TextBox   ID= "TextBox2 "   Text= ' <%#Eval( "考查成绩 ")%> '     runat= "server "> </asp:TextBox>
                                                </EditItemTemplate>


                                                <ItemTemplate>
                                                        <asp:Label   ID= "Label4 "   runat= "server "   Text= ' <%#Eval( "考查成绩 ")   %> '> </asp:Label>
                                                </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:CommandField   ShowEditButton= "True "> </asp:CommandField>            
                                </Columns>
                      </asp:GridView>
               
感谢各位了



[解决办法]
GVeditor_RowUpdated?
代码写在
GVeditor_RowUpdating事件里
[解决办法]
你确认一下,数据库没有更新吗?还是你没有重新绑定?
事件没写对?
[解决办法]
http://msdn2.microsoft.com/zh-cn/library/aa479339.aspx

GridView各种操作的例子和代码
[解决办法]
(1)更新的时机不对,你的事件更新完才能触发。
(2)更新不用写代码,邦定SqlDataSource,并写它的Update语句就可以了,注意取原值的参数用@original_字段名,新值取@字段名,OldParametersFormat属性设置为@original_{0}

热点排行