Can't retreave new value from Datagrid onUpdate Command

Discussion in 'ASP .Net' started by =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 3, 2005.

  1. 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
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 3, 2005
    #1
    1. Advertising

  2. 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
    >
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 3, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. San Diego Guy
    Replies:
    0
    Views:
    544
    San Diego Guy
    Aug 7, 2003
  2. =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=

    how can I retreave a key from view state

    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Jul 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    390
    Eliyahu Goldin
    Jul 28, 2005
  3. Andreas Klemt
    Replies:
    0
    Views:
    293
    Andreas Klemt
    Oct 8, 2003
  4. Replies:
    2
    Views:
    449
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
  5. Rene Ivon Shamberger

    insert and retreave for std::set()

    Rene Ivon Shamberger, Oct 9, 2012, in forum: C++
    Replies:
    5
    Views:
    328
    Jorgen Grahn
    Oct 10, 2012
Loading...

Share This Page