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