Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Variable = to Repeater Item

Status
Not open for further replies.

kliz0328

Programmer
Nov 7, 2005
138
0
0
US
I was wondering if it is possible to set a variable equal to a repeater item. It tried this but it siad that Container is not decalred.
Code:
Dim Fielding() as String
Dim strItem as String

Fielding = Container.DataItem("FieldingDesc")

For each strItem in Fielding
 
>>I was wondering if it is possible to set a variable equal to a repeater item.

try this:
<itemtemplate>
<%# MyFunc(DataBinder.Eval(Container.DataItem("FieldingDesc"))) %>

in ur CB:

public function MyFunc(TheRptCmd as string) as string
'This function will execute for every row. TheRptCmd will get the value of each row
end function

Known is handfull, Unknown is worldfull
 
You should try to stay clear of classic ASP methods such as the one suggested. Instead, use the ItemDataBound event and get the value there.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
thats ASP??? kindly try that code in ASP dude and get back to me...

Known is handfull, Unknown is worldfull
 
Re-read what I said. I said it was a classic ASP method (i.e. inline code) not that it was classic ASP code. ASP.NET is trying to break away from including code within the page and seperate it into a different code page. The method that you suggested is what we should be trying to avoid.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
meaning totally do away with the <%# %> itself? or just the MyFunc() defn.

<%# %> is used very commonly...

Known is handfull, Unknown is worldfull
 
meaning totally do away with the <%# %> itself? or just the MyFunc() defn.

<%# %> is used very commonly...
I mean the call to the function. There is no need to include extra code in the HTML as this is a server-side function that you want to call and there is an ItemDataBound event created specifically for this purpose.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>There is no need to include extra code in the HTML as this is a server-side function that you want to call and there is an ItemDataBound event created specifically for this purpose.

i would say that this is a blanket stmt.

lets take an e.g.

if i get the value "Y" then i need to print "Yes" or i need to print "No". this conversion is done by a simple function that accepts the data from the Reader / DataSet as input.

if i had to do the same in the ItemDataBound event then:
-> i need to differentiate between normal items, headers and footers. This event fires for ALL the three types.
-> i need to find the correct column / label. get the text into a variable.
-> Then we NEED to CALL the function ANYWAY to convert the values set the text back.

in my method:
Nothing, the function is called as is and thats all. even the function's defn is in CB.

advantages:
-> Coding is lesser
-> Logically i this method must be faster as it gets called only for the row items.


Known is handfull, Unknown is worldfull
 
You are missing the whole point of seperating logic from UI. If someone has to look into an application (or are developing it in seperate teams like "designers" and "developers"), they should be able to:

1) Look at the relevant code layer to find where data is being set.
2) Work on their own layer and not worry about what effects modifying a line will have on the other "teams" layer.

In your suggested method they would have to look at both the code behind page and the UI (which should only contain information on how to display the data, not include code to call functions etc). It's basicically Object Orientation that ASP.NET is promoting and your method goes against this model. It's not incorrect what you have suggested but there are better methods and these need to be pointed out to the poster and any future readers of this post.

I suggest that you read up on some articles on the subject of seperating UI from UI logic as it can become a big nuisance when working on large scale applications (and it's better practice to take note of this scalability and apply it when developing your own applications).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>It's not incorrect what you have suggested but there are better methods and these need to be pointed out to the poster and any future readers of this post.

what are all the points to consider before a method is declared as good or bad?

e.g.:
-> Scalability
-> Ease of code
-> Practicality

etc.

because my personal opinion is that we should not close out on a method because it doesnt follow a particular principle. it may score on other counts. that is also important.

i have widely used such functions and have not faced a problem till now.

the usual approach that i do is to write a helper class with shared modules that will caryy such common functions. I call these helper classes in my code.

it has considerably cut out on my code and time...

Known is handfull, Unknown is worldfull
 
the usual approach that i do is to write a helper class with shared modules that will caryy such common functions. I call these helper classes in my code.

it has considerably cut out on my code and time...
And that's definately something that you've done well. You've used an Object Orientated method to create a class of useful functions. You've then created an instance of that class and performed whatever function is necessary and all your code has been seperated and it is easy to follow and can be changed from one place and it will affect every other method that calls it.

With the example you gave above, it doesn't really follow that model. For example, it may be easier and less code to write:
Code:
<asp:Label ID="Label1" runat="server" Text="<% myVariable %>"></asp:Label>
than writing
Code:
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label1.Text = myVariable
    End Sub
However, I'm sure that you'll see that the benefits of the second approach far outweigh the first?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
it does, looking from the code seperation model, but again like i said, it really depends on many points. 99.99% normally thats the mode used. but sometimes i do use the old ASP model to make things easier...

Known is handfull, Unknown is worldfull
 
I am trying to split the item from the table into an array then loop through the array values and display pics side by side like this Is there a way to do this or do I have to use the classic asp way of looping through the record set like I am here with dbreader?
Code:
<%
Dim Fielding() as String
Dim Fields
Dim strItem as String
Dim GG



Fields = dbreader("FieldingDesc")
Fielding= Fields.Split(",")

For each strItem in Fielding
%>
<TD>

<% If strItem <> "NA" Then
Response.write( "<img src='1Images/" &  strItem & "'>")
End If
%>

</TD>
<% Next %>
 
oh no, i guess u can set an Array as a datasource for the repeater, try that out...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top