Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can't retreave new value from Datagrid onUpdate Command

Reply
Thread Tools

Can't retreave new value from Datagrid onUpdate Command

 
 
=?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
Guest
Posts: n/a
 
      02-03-2005
Another simple one:
1. I'm using code behind
2. the sub is not labeled private will not take.
3. I can pass the value of the key to the update sub, but the sub can only
retreive the origional value not the value from the textbox. don't understand
why and i'd like some help.
thanks
kes
CODE: (sorry it's a lot)
FORM
<form id="Form1" method="post" runat="server">
<table cellSpacing="1" cellPadding="1" width="300" border="1">
<tr>
<td><asp:label id="lblLabel1" runat="server" Height="32px"
Width="88px">Edit Typesss</asp:label></td>
<td><asp:linkbutton id="lnkToMain" runat="server" Height="24px"
Width="208px">To Main</asp:linkbutton></td>
<td><asp:label id="txtLabel1" runat="server" Height="48px"
Width="280px">Label</asp:label></td>
</tr>
<tr>
<td><asp:textbox id="txtNewStone" runat="server" Height="32px"
Width="192px" EnableViewState="False"></asp:textbox></td>
<td colSpan="2"><asp:button id="btnAddNew" runat="server" Width="152px"
Text="Add New Stone Type"></asp:button></td>
</tr>
<tr>
<td colSpan="3">
<asp:datagrid id="dGrdTyp" runat="server" Height="240px" Width="336px"
AutoGenerateColumns="False"
AllowSorting="True" DataKeyField="typID"
OnUpDateCommand="DoItemUpdate" OnEditCommand="DoItemEdit"
OnCancelCommand="DoItemCancel">
<Columns>
<asp:BoundColumn DataField="typID" ReadOnly="True"
HeaderText="ID"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Edit">
<ItemTemplate>
<asp:Label Text='<%# Container.DataItem("typName") %>'
runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtStone" Text='<%# Container.DataItem("typName")
%>' runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
</Columns>
</asp:datagrid></td>
</tr>
</table>
</form>
sub in the code behind:

Sub DoItemUpdate(ByVal objSource As Object, ByVal objArgs As
DataGridCommandEventArgs)
Dim conUpdateType As OleDbConnection
Dim cmdUpdateType As OleDbCommand
Dim objStoneCtrl As TextBox
Dim strthsType As String
objStoneCtrl = CType(objArgs.Item.FindControl("txtStone"), TextBox)
strthsType = objStoneCtrl.Text
'Response.Write(txtNewStone.Text)
txtLabel1.Text = objStoneCtrl.Text & ", " &
dGrdTyp.DataKeys(objArgs.Item.ItemIndex)
conUpdateType = New
OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=" & thsSitePath
& "db\damarstone.mdb")
cmdUpdateType = New OleDbCommand("Update Typ Set typName = @thsType
where TypID = @thsID", conUpdateType)
'cmdUpdateType.Parameters.Add("@thsID",
dGrdTyp.DataKeys(objArgs.Item.ItemIndex))
'cmdUpdateType.Parameters.Add("@thsType", objStoneCtrl.Text)
conUpdateType.Open()
' cmdUpdateType.ExecuteNonQuery()
conUpdateType.Close()
dGrdTyp.EditItemIndex = -1
BindDataGrid()
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
Guest
Posts: n/a
 
      02-03-2005
got it to work by doing the following: StrSQLcmd = "Update Typ Set typName =
'" & objStoneCtrl.Text & "' where TypID = @thsID" and then submitting this
to the commant. Wish i knew why????
.........please, any one..????

"Kurt Schroeder" wrote:

> Another simple one:
> 1. I'm using code behind
> 2. the sub is not labeled private will not take.
> 3. I can pass the value of the key to the update sub, but the sub can only
> retreive the origional value not the value from the textbox. don't understand
> why and i'd like some help.
> thanks
> kes
> CODE: (sorry it's a lot)
> FORM
> <form id="Form1" method="post" runat="server">
> <table cellSpacing="1" cellPadding="1" width="300" border="1">
> <tr>
> <td><asp:label id="lblLabel1" runat="server" Height="32px"
> Width="88px">Edit Typesss</asp:label></td>
> <td><asp:linkbutton id="lnkToMain" runat="server" Height="24px"
> Width="208px">To Main</asp:linkbutton></td>
> <td><asp:label id="txtLabel1" runat="server" Height="48px"
> Width="280px">Label</asp:label></td>
> </tr>
> <tr>
> <td><asp:textbox id="txtNewStone" runat="server" Height="32px"
> Width="192px" EnableViewState="False"></asp:textbox></td>
> <td colSpan="2"><asp:button id="btnAddNew" runat="server" Width="152px"
> Text="Add New Stone Type"></asp:button></td>
> </tr>
> <tr>
> <td colSpan="3">
> <asp:datagrid id="dGrdTyp" runat="server" Height="240px" Width="336px"
> AutoGenerateColumns="False"
> AllowSorting="True" DataKeyField="typID"
> OnUpDateCommand="DoItemUpdate" OnEditCommand="DoItemEdit"
> OnCancelCommand="DoItemCancel">
> <Columns>
> <asp:BoundColumn DataField="typID" ReadOnly="True"
> HeaderText="ID"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Edit">
> <ItemTemplate>
> <asp:Label Text='<%# Container.DataItem("typName") %>'
> runat="server" />
> </ItemTemplate>
> <EditItemTemplate>
> <asp:TextBox ID="txtStone" Text='<%# Container.DataItem("typName")
> %>' runat="server" />
> </EditItemTemplate>
> </asp:TemplateColumn>
> <asp:EditCommandColumn UpdateText="Update" CancelText="Cancel"
> EditText="Edit"></asp:EditCommandColumn>
> </Columns>
> </asp:datagrid></td>
> </tr>
> </table>
> </form>
> sub in the code behind:
>
> Sub DoItemUpdate(ByVal objSource As Object, ByVal objArgs As
> DataGridCommandEventArgs)
> Dim conUpdateType As OleDbConnection
> Dim cmdUpdateType As OleDbCommand
> Dim objStoneCtrl As TextBox
> Dim strthsType As String
> objStoneCtrl = CType(objArgs.Item.FindControl("txtStone"), TextBox)
> strthsType = objStoneCtrl.Text
> 'Response.Write(txtNewStone.Text)
> txtLabel1.Text = objStoneCtrl.Text & ", " &
> dGrdTyp.DataKeys(objArgs.Item.ItemIndex)
> conUpdateType = New
> OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=" & thsSitePath
> & "db\damarstone.mdb")
> cmdUpdateType = New OleDbCommand("Update Typ Set typName = @thsType
> where TypID = @thsID", conUpdateType)
> 'cmdUpdateType.Parameters.Add("@thsID",
> dGrdTyp.DataKeys(objArgs.Item.ItemIndex))
> 'cmdUpdateType.Parameters.Add("@thsType", objStoneCtrl.Text)
> conUpdateType.Open()
> ' cmdUpdateType.ExecuteNonQuery()
> conUpdateType.Close()
> dGrdTyp.EditItemIndex = -1
> BindDataGrid()
> End Sub
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
insert and retreave for std::set() Rene Ivon Shamberger C++ 5 10-10-2012 12:57 PM
Datagrid cancel command does not work when adding new record Julia B ASP .Net Web Controls 2 04-11-2006 12:42 PM
how can I retreave a key from view state =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= ASP .Net 2 07-28-2005 04:21 PM
Call Datagrid Command column outside datagrid Dave ASP .Net 0 11-20-2003 11:11 AM
copying value of DDL in a Datagrid "pre-edit command" to value in "post edit command" San Diego Guy ASP .Net 0 08-07-2003 08:59 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57