SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FindControl and values...

    Hi,

    I have a repeater that is populated via databinding by dynamic content. Within this repeater could lie anywhere from 1-10 checkboxes, textboxes, or radio buttons. I am able to get the values inputted from the user into the textboxes using:
    for(int x=0; x<=rptMulti.Items.Count -1; x++)
    {
    TextBox txtAdditional = (TextBox)rptMulti.Items[x].FindControl("txtAdditional");
    Response.Write(txtAdditional.Text);
    }

    But, what I would like to know is how can i store each value into its own variable so I can use this variable to input the data into a database via a stored procedure? same goes for checkboxes and radiobuttos. What this is is a survey thats dynamically created by admins for multiple users. Once the user logs in he/she is viewed with this link to take the survey. What i need to store is those values that user inputted.

    Regards,

    tdela

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are a number of ways to store them, the simplist and quickest using one of the new Generic collections in .NET to, say a List<string>:
    Code:
     List<string> additionals = new List<string>();
     for (int x = 0; x < rptMulti.Items.Count; x++ )
     {
        TextBox txtAdditional = (TextBox)rptMulti.Items[x].FindControl("txtAdditional");
        addtionals.Add(txtAdditional.Text);
     }
    And to access them:
    Code:
     foreach (string additional in additionals ) 
     {
        // Insert into database
     }
    There are a numbre of Generic collections, some that might what your trying to do, you can see them here: http://msdn2.microsoft.com/en-us/lib...s.generic.aspx

  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh this is for .NET 2.0, i forgot to mention we're still stuck on 1.1, is there still an alternative?

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An ArrayList would do the job in 1.1: http://msdn2.microsoft.com/en-us/lib...arraylist.aspx

  5. #5
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I'll give that a try. We really need to upgrade over here

  6. #6
    SitePoint Guru Raskolnikov's Avatar
    Join Date
    Jul 2003
    Location
    USA
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tdela, i would like to hear your results on this issue. I will be tackling the same issue very soon.

  7. #7
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will let you know as soon as I figure it out. The result that dhtmlgod gave me were a start but that still doesn't help me to determine results. I'm onto something new so i'll keep you updated as I go.

    T

  8. #8
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could always look at doing it more structured with a DataTable. This will make it easier to sort/filter results as it acts like an in-memory database. You can also easily save it as XML, saving time to work out a database structure to hold this kinda of fluid data. I have some code that might be similar to what your looking for kicking around, should be in 1.1 too, was for a quiz a few years ago. I'll look it out for ya'

  9. #9
    SitePoint Guru Raskolnikov's Avatar
    Join Date
    Jul 2003
    Location
    USA
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    see here is my problem. I can get the data i need from the non-dynamic parts of the form. however, a member has to select how many other members he/she is submitting. That Drop Down Box controls how many member entry areas show up. SO if member one needs to submit 2 other members, then two rows show up each with its own firstName and LastName textboxes, then a dropdownbox containing a list of clubs to select from.

    when the repeater creates those entry fields, it creates them with a wierd generated name.

    how do you go about finding the data from an item who's name and id are dynamically created?

    Ras

  10. #10
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll want to loop through all the controls of each Repeater item, here is some untested code to get you started, this is based on the ItemCommand:
    Code:
    foreach (Control control in e.Item.Controls)
    {
       // you'll want to check that the control is and then cast it before you access any properties
    }
    If your going to be accessing the controls with a handler outwith the Repeater, you'll want to loop through each item within the Repeater then have the above loop

  11. #11
    SitePoint Guru Raskolnikov's Avatar
    Join Date
    Jul 2003
    Location
    USA
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The foreach method gets the job done for me.

    Ras


Bookmarks

Posting Permissions

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