Results 1 to 2 of 2

Thread: [RESOLVED] Losing my values

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    Resolved [RESOLVED] Losing my values

    Hi All

    I'm working on a javascript that puts the value of a select into a htmlinputtext.

    The template looks like this:
    Code:
    <asp:TemplateField>
             <ItemTemplate>
             <asp:Label runat="server" ID="lbl" Text='<%# Bind("OrderDate") %>'></asp:Label>
             <input type="text" runat="server" ID="txtOrderDate" />
                 <asp:DropDownList runat="server" ID="dd">
                 <asp:ListItem Value="Test Value One">Test Value One</asp:ListItem>
                 <asp:ListItem Value="Test Value Two">Test Value Two</asp:ListItem>
                 </asp:DropDownList>
             </ItemTemplate>
             </asp:TemplateField>
    In the rowdatabound, I've got the following code:
    Code:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim txt As HtmlInputText = e.Row.FindControl("txtOrderDate")
                Dim dd As DropDownList = e.Row.FindControl("dd")
                Dim str As String = "var x = getElementById('" & txt.ClientID & "');" & "x.value = this.options[selectedIndex].text;"
                dd.Attributes.Add("onChange", str)
            End If
    
        End Sub
    So far so good. I guess.

    Here's where it gets messed up:

    Code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim txt As HtmlInputText = gvr.FindControl("txtOrderDate")
            'Dim dd As DropDownList = gvr.FindControl("dd")
            Dim i As Integer = 0
            Dim str As String = String.Empty
            For i = 0 To GridView1.Rows.Count - 1
                Dim g As GridViewRow = GridView1.Rows(i)
                Dim t As HtmlInputText = g.FindControl("txtOrderDate")
                str &= t.Value
            Next
            Label1.Text = str
        End Sub
    The javascript works. However, whether its the javascript or I type something in the box, when I push button1, I get no values. Nothing. The Label is blank.
    If I bind the text box, I get the values.

    Resolved: I could have sworn I already tried this, but I switched from an input runat=server to a textbox and it works like a champ.

    Thanks in advance
    Last edited by Rocketdawg; Jul 14th, 2008 at 09:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width