在我点击编辑时,修改完数据时点确定后不能更改数据,我把代码贴出来了,请大家帮帮忙吧,看哪有问题啊?
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 104px"
HeaderStyle-BackColor="#BCBCBC" Width="100%" AllowPaging="True" PageSize="15" PagerStyle-Visible="false"
OnEditCommand="datagrid1_edit" OnCancelCommand="datagrid1_cancel" OnUpdateCommand="datagrid1_update"
OnDeleteCommand="datagrid1_delete" DataKeyField="id" runat="server" BackColor="WhiteSmoke"
BorderColor="#C0C0FF" ForeColor="Transparent">
<HeaderStyle BackColor="#BCBCBC"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="确定" CancelText="取消" EditText="编辑">
<ItemStyle Wrap="False"></ItemStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="删除" CommandName="delete">
<ItemStyle Wrap="False"></ItemStyle>
</asp:ButtonColumn>
</Columns>
<PagerStyle Visible="False"></PagerStyle>
</asp:DataGrid>
Sub DataGrid1_update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim txtid, txttypeid, txtpro_id, txtpname, txtpimageurl, txtpsprice, txtphprice, txtpaddtime, txtpintro, txtcc, txtyxq As TextBox
txtid = e.Item.Cells(3).Controls(0)
txttypeid = e.Item.Cells(4).Controls(0)
txtpro_id = e.Item.Cells(5).Controls(0)
txtpname = e.Item.Cells(6).Controls(0)
txtpimageurl = e.Item.Cells(7).Controls(0)
txtpsprice = e.Item.Cells(8).Controls(0)
txtphprice = e.Item.Cells(9).Controls(0)
txtpaddtime = e.Item.Cells(10).Controls(0)
txtpintro = e.Item.Cells(11).Controls(0)
Dim strsql As String
strsql = "update product set typeid='" & txttypeid.Text & "',pro_id='" & txtpro_id.Text & "',pname='" & txtpname.Text & "',pimageurl='" & txtpimageurl.Text & "',psprice='" & txtpsprice.Text & "',phprice='" & txtphprice.Text & "',paddtime=#" & Now() & "#,pintro='" & txtpintro.Text & "' where id=" & DataGrid1.DataKeys(CInt(e.Item.ItemIndex))
Dim conn As New SqlConnection("server=(local);database=xf;uid=sa;pwd=;")
Dim cmd As New SqlCommand(strsql, conn)
Dim exp As Exception
Try
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Catch exp
Label3.Text = "发生错误,没有正常更新记录,请重新修改!"
End Try
DataGrid1.EditItemIndex = -1
Call myDataBind()
End Sub
[此贴子已经被作者于2006-11-16 10:05:36编辑过]