开发者

Fetching the values of dynamic textboxes vb.net

开发者 https://www.devze.com 2023-03-30 08:04 出处:网络
If i have multiple textboxes with the same Id and name in a form, how to fetch there values separately in vb.net? can anyone help me? thanks in advance.

If i have multiple textboxes with the same Id and name in a form, how to fetch there values separately in vb.net? can anyone help me? thanks in advance.

in javascript iv used fetched them like this

var b=document.getElementById('TextBox') 
va开发者_StackOverflow社区r a=b.length; 
for(var i=0; i<a; i++) { 
var text=b[i]; 
alert(text) 
} 


You should have a seperate ID from them. How are you generating those text boxes ?

Generate the textboxes in a loop and assign them the incrementing IDs, for ex box1,box2 ....


Here is an example for vb.net

For Each oControl As Control In Page.Controls
            If TypeOf oControl Is TextBox Then
                Dim txtbox As TextBox = CType(oControl, TextBox)
                txtbox.Text = Date.Now.ToString
            End If
        Next 

in your case something like this assuming your textboxes ids are like txtTestTxt0, txtTestTxt1,txtTestTxt2 and so on

   For x As var = 0 To Page.Controls
    If Page.FindControls("txtTestTxt" & x) IsNot Nothing Then
        Dim tb As TextBox = DirectCast(Page.FindControl("txtTestTxt" & x.tostring()), TextBox)
        myval = tb.Text
    End If
Next
0

精彩评论

暂无评论...
验证码 换一张
取 消