Hi All
I'm working on a javascript that puts the value of a select into a htmlinputtext.
The template looks like this:
In the rowdatabound, I've got the following code: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>
So far so good. I guess.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
Here's where it gets messed up:
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.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
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


Reply With Quote
