473,324 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Can't retreave new value from Datagrid onUpdate Command

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

Nov 19 '05 #1
1 1573
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brett Hargreaves | last post by:
Hi, I'm having trouble with the datagrid update command. I have a datagrid called grid that poulates itself with data in the page load event. When I click the edit button it takes me into...
0
by: Funbeat | last post by:
Hi everybody, A very strange problem with WebControls : A Datagrid in an ASp.net application; Bound with a dataset through ado.net; The updatable columns are dynamically created; When I try...
0
by: John Spiegel | last post by:
Hi all, As usual, I have found a way to make the straightforward, textbook example fail. I have a datagrid that supports editing. When I edit a row then fire the update, the value that gets...
1
by: RockNRoll | last post by:
I'm new to ASP.NET and need to filter a datagrid based on a textbox value. I have a working datagrid and would like the WHERE part of my SQL statement to call the value of a textbox and refresh...
2
by: saleek | last post by:
Hi, I am trying to figure out why my datagrid has stopped firing the page and sort commands. Scenario: I originally had template columns in my datagrid and had set up custom bi-directional...
2
by: WebBuilder451 | last post by:
I have a short datalist that has a key field. on item select i want to open a panel that has the details from the record selected. If at all possible i do not want to re-run the sp, re-fill the...
0
by: jason | last post by:
Hello everyone. I am trying to write some custom command events into a DataGrid. The command that is currently giving me trouble is an "Add" custom command in the footer of a template column. ...
2
by: yasodhai | last post by:
Hi, I used a dropdown control bind to a datagrid. <EditItemTemplate> <asp:DropDownList ID="FldType_edit" Runat="server" DataSource='< %#GetFieldType()%>' DataTextField="Type" />...
3
by: ordit | last post by:
hey everybody!, Im new in the forum & to vb6. I want to connect a datagrid with the .datasource, .datamember prperties. my command requires a parameter: select order,name from tabe1 where...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.