|
-
Jul 20th, 2003, 10:55 AM
#1
Thread Starter
yay gay
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/
-
Jul 20th, 2003, 10:58 AM
#2
PowerPoster
You do not need to use the Eval() method in this instance. Just use the current DataItem.
-
Jul 20th, 2003, 10:59 AM
#3
Thread Starter
yay gay
\m/  \m/
-
Jul 20th, 2003, 11:03 AM
#4
Thread Starter
yay gay
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/
-
Jul 20th, 2003, 12:23 PM
#5
PowerPoster
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.
-
Jul 20th, 2003, 12:50 PM
#6
Thread Starter
yay gay
ah tks
\m/  \m/
-
Jul 20th, 2003, 12:52 PM
#7
Thread Starter
yay gay
also, why does it have to be public? just for curiosity
\m/  \m/
-
Jul 20th, 2003, 01:03 PM
#8
PowerPoster
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 " - ".
-
Jul 20th, 2003, 01:25 PM
#9
Thread Starter
yay gay
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/
-
Jul 20th, 2003, 04:16 PM
#10
PowerPoster
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.
-
Jul 20th, 2003, 04:21 PM
#11
Thread Starter
yay gay
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|