标题:[讨论][求助]简单的gridview更新问题
只看楼主
独孤幽灵
Rank: 1
等 级:新手上路
帖 子:115
专家分:0
注 册:2005-11-24
 问题点数:0 回复次数:3 
[讨论][求助]简单的gridview更新问题



上图只是简单表示下意思,不代表下面程序

点击编辑后,我更新里面的内容
然后点击更新,可是就是更新不了

更新按钮的代码
protected void GVeditor_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
try
{
string cj = ((TextBox)e.NewValues[5]).Text;//.Cells[5].Controls[0]).Text;//成绩
string kccj = ((TextBox)e.NewValues[6]).Text;//.Cells[6].Controls[0]).Text;//考查成绩
string xk = ((TextBox)e.NewValues[1]).Text;//.Cells[1].Controls[0]).Text;//学生ID
string km = ((TextBox)e.NewValues[4]).Text;//.Cells[4].Controls[0]).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;
}


<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>

[此贴子已经被作者于2007-1-5 12:28:36编辑过]

搜索更多相关主题的帖子: gridview 
2007-01-05 12:25
YSKING
Rank: 5Rank: 5
来 自:中国绿城
等 级:贵宾
威 望:16
帖 子:1380
专家分:25
注 册:2006-11-11
得分:0 
TextBox cj = (TextBox)e.Item.Cells[5].Controls[0];
03的是这样用,不知道你05的行不行,试下吧

仍然自由自我,永远高唱我歌,走遍千里...
2007-01-05 12:32
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:0 
把 cmdtext  输出来看一下就知道了.

飘过~~
2007-01-05 15:16
独孤幽灵
Rank: 1
等 级:新手上路
帖 子:115
专家分:0
注 册:2005-11-24
得分:0 
看来大家都没做过啊

2007-01-07 10:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-114380-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.616179 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved