开发者

How to dynamically construct a control name in ASP.NET?

开发者 https://www.devze.com 2023-02-14 05:15 出处:网络
I am iterating through an array: Dim dbConfig As New pbu_housingEntities Dim possible() As String = {\"FROD\", \"FRCD\", \"SOOD\", \"SOCD\", \"JROD\", \"JRCD\", \"SROD\", \"SRCD\", \"SR5OD\", \"SR5CD

I am iterating through an array:

Dim dbConfig As New pbu_housingEntities
    Dim possible() As String = {"FROD", "FRCD", "SOOD", "SOCD", "JROD", "JRCD", "SROD", "SRCD", "SR5OD", "SR5CD"}
    For Each value As String In possible
        Dim current_value = value
        Dim exists = From p In dbConfig.Configs _
                     Where p.Descr开发者_StackOverflowiption = current_value
                     Select p

        If exists.Count.Equals(0) Then
            Dim create As New Config
            create.Description = current_value
            dbConfig.Configs.AddObject(create)
            dbConfig.SaveChanges()
        Else
            Dim update_query = (From p In dbConfig.Configs _
                                Where p.Description = current_value _
                                Select p)
            update_query.First.Description = current_value
            update_query.First.dateValue = 
        End If
    Next

Towards the end of the array you can see update_query.First.dateValue =, I'd like to do something like this:

update_query.First.dateValue = "txt" + current_value + ".Text"

But I don't want it to return the literal txtcurrent_value.Text, but rather to return the text value of txtcurrent_value.Text. This is easy to do, if you know each control name - but in this case I'm iterating, otherwise I could do:

update_query.First.dateValue = txtNameofControl.Text


Get a reference to the control like this:

TextBox tb = Page.FindControl("txt" + current_value) as TextBox;
update_query.First.dateValue = tb.Text;
0

精彩评论

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