Results 1 to 11 of 11

Thread: how to databind a string array

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    how to databind a string array

    how do i do this? i've created a itemtemplate with the repeater control. now i want every button to have the text property binded to the array..how do i do this? i made the following code:
    Code:
    string[] array = { "um", "dois", "tres" };
    Repeater1.DataSource = array;
    Repeater1.DataBind();
    but as natural it isnt binding the button..what is the code i should put in the button so it is binded in the text perperty? when using databases i could put this:
    Code:
    Text='<%# DataBinder.Eval(Container.DataItem, "Message") %>'
    but seems not to be working(because the database column was Message and now it isnt..what should i put instead of "Message"? or should i use another totally opost code? help plz!
    \m/\m/

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You do not need to use the Eval() method in this instance. Just use the current DataItem.

    Code:
       Container.DataItem

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hm yeah worked great tks
    \m/\m/

  4. #4

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i have another question about databinding..is it possible that i can process the data before it is databinded? for example if i want to bind an array that has "ONE", "TWO" and "THREE" i would want to put "This is number: ONE", "This is number: TWO", etc or whatever code i want..can this be done?
    \m/\m/

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Originally posted by PT Exorcist
    i have another question about databinding..is it possible that i can process the data before it is databinded? for example if i want to bind an array that has "ONE", "TWO" and "THREE" i would want to put "This is number: ONE", "This is number: TWO", etc or whatever code i want..can this be done?
    Yes you can, you just need to create a public method in your code, then call that method for the text. Make sure the method returns a string type.

    Example:
    Text='<%# MyMethod(Container.DataItem) %>'

    MyMethod will take in a string or object data type as an argument, and you will pass the dataitem as that. Then the return type from the method itself will be assigned to the text property.

  6. #6

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ah tks
    \m/\m/

  7. #7

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    also, why does it have to be public? just for curiosity
    \m/\m/

  8. #8
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Originally posted by PT Exorcist
    also, why does it have to be public? just for curiosity
    The method has to be publicly exposed for the control to have access to it. Also, you can add a handler for the ItemDataBound event, which happens just after each row is bound to its datasource. In this method, you have access to the current row, as well as the datasource. I use this for instance, where I want to replace zero's with " - ".

  9. #9

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i have another question!
    with the repeater control is it possible that instead of having to put item template code, header template etc in the HTML viewer i can put it thru c# code? if yes how?
    \m/\m/

  10. #10
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    What you can do is add a placeholder within the itemtemplate and handle the ItemDataBound event. Within this event, you can add controls to the placeholder.

  11. #11

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm so there is no direct way of doing this? i see the repeater control has HeadItemTemplate property or something like that..cant it be worked out thru there(i tried but didnt find a way)
    \m/\m/

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