Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Controlling what is regarded as Item/AlternatingItem

Reply
Thread Tools

Controlling what is regarded as Item/AlternatingItem

 
 
K Viltersten
Guest
Posts: n/a
 
      10-04-2009
I'm reworking a repeater that previously used

if (e.Item.ItemType == ListItemType.Item)
css += "plain";
else
css += "alter";

Some of the rows will now be hidden, which
creates the ugly appearance of several
consecutive and visible rows to share the
same css (e.g. alter).

I need to manipulate the repeater to
disregard certain rows upon binding the
data. So to speak - skip a line.

One way to do this would probably be a
static flag, the status of which would
change with every non-hidden row but that's
a) ugly,
b) non object oriented,
c) blah-ish.

Any suggestions?

--
Regards
K Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.

 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-04-2009
One thing I would look into is using the AlternatingItemTemplate. This uses
the same DataSource as the ItemTemplate, but it allows you to specify a
different template. Also, what are the conditions that determine which rows
will be displayed and hidded? You may want to look into the ItemDataBound
event for this, and set the desired CSS from inside the ItemDataBound event
after determining whether you want to display or hide the row. Hopefully
this helps.
--
Nathan Sokalski
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/

"K Viltersten" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm reworking a repeater that previously used
>
> if (e.Item.ItemType == ListItemType.Item)
> css += "plain";
> else
> css += "alter";
>
> Some of the rows will now be hidden, which creates the ugly appearance of
> several consecutive and visible rows to share the same css (e.g. alter).
>
> I need to manipulate the repeater to disregard certain rows upon binding
> the data. So to speak - skip a line.
>
> One way to do this would probably be a static flag, the status of which
> would change with every non-hidden row but that's
> a) ugly,
> b) non object oriented,
> c) blah-ish.
>
> Any suggestions?
>
> --
> Regards
> K Viltersten
> ----------------------------------------
> May all spammers die an agonizing death;
> have no burial places; their souls be
> chased by demons in Gehenna from one room
> to another for all eternity and beyond.
>



 
Reply With Quote
 
 
 
 
K Viltersten
Guest
Posts: n/a
 
      10-04-2009
> One thing I would look into is using the
> AlternatingItemTemplate. This uses the
> same DataSource as the ItemTemplate, but
> it allows you to specify a different
> template.


Well, that's what i'm using. Perhaps i should
clarify the code a bit more.

ListItemType t = e.Item.ItemType;
if (t == ListItemType.AlternatingItem)
css += "alter";
else if (t == ListItemType.Item)
css += "plain";

> You may want to look into the ItemDataBound
> event for this, and set the desired CSS
> from inside the ItemDataBound event...


The setup above IS ALREADY in the event
handler for data binding. Where else could
it be placed, anyway?

So, the question is, as i expressed it in my
original question, how one can manipulate
the list item type of a given item, depending
on the outcome of their predecessors and
successors.

Thank you.

--

Regards
Konrad Viltersten
--------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-05-2009
First of all, since your code will ALWAYS give your ItemTemplate the css
class "plain" and AlternatingItemTemplate the css class "alter", why are you
doing it in the codebehind at all? I would have done something like the
following:

<asp:Repeater ID="repSample" runat="server">
<ItemTemplate>
<asp:Label ID="lblItemContent" runat="server" Text="ItemTemplate Label"
CssClass="plain"/>
</ItemTemplate>
<AlternatingItemTemplate>
<asp:Label ID="lblAlternatingItemContent" runat="server"
Text="AlternatingItemTemplate Label" CssClass="alter"/>
</AlternatingItemTemplate>
</asp:Repeater>

I just used Labels as example content, but the point is that the styles are
different in the two templates without the need for anything in the
codebehind.

As for your question about manipulating an item based on other items, I
would suggest doing something that would involve the following:

In the PreRender event, use the Items property of the Repeater to view and
modify any items you wish to modify.

Another approach that you could use would be to, in the ItemDataBound use
the e.Item.ItemIndex property to get any necessary data from the Repeater's
DataSource. To do this, you will use when getting the data from the
Repeater's DataSource, you will do stuff like use e.Item.ItemIndex-1 as the
index to get data about the previous item or e.Item.ItemIndex+1 as the index
to get the next item.

Hopefully this helps. Because I have not seen your code and do not know what
the goal of your project is, I cannot say whether or not there is another or
better way, but when using databinding it is usually best to try to avoid
basing the formatting of one item on another item. Good Luck!
--
Nathan Sokalski
(E-Mail Removed)
http://www.nathansokalski.com/

"K Viltersten" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> One thing I would look into is using the AlternatingItemTemplate. This
>> uses the same DataSource as the ItemTemplate, but it allows you to
>> specify a different template.

>
> Well, that's what i'm using. Perhaps i should
> clarify the code a bit more.
>
> ListItemType t = e.Item.ItemType;
> if (t == ListItemType.AlternatingItem)
> css += "alter";
> else if (t == ListItemType.Item)
> css += "plain";
>
>> You may want to look into the ItemDataBound event for this, and set the
>> desired CSS from inside the ItemDataBound event...

>
> The setup above IS ALREADY in the event handler for data binding. Where
> else could
> it be placed, anyway?
>
> So, the question is, as i expressed it in my
> original question, how one can manipulate the list item type of a given
> item, depending
> on the outcome of their predecessors and successors.
>
> Thank you.
>
> --
>
> Regards
> Konrad Viltersten
> --------------------------------
> May all spammers die an agonizing death;
> have no burial places; their souls be
> chased by demons in Gehenna from one room
> to another for all eternity and beyond.



 
Reply With Quote
 
K Viltersten
Guest
Posts: n/a
 
      10-05-2009
As i mentioned in the original post, some of
the rows will be hidden (regardless of them
being styled to plain/alter.

So, by only adding the style the way you
described, i might get to SEE only plain
rows (if the alternating happen to be hidden
because of the new conditions).

Index will not work either, for the same
reason.

I went for boolean flag that changes the
state for each data bind event fired, except
for those that are hidden. I'm not very
satisfied with that solution, though.

Any suggestion to that?

Thanks.

--
Regards
K Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.





"Nathan Sokalski" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> First of all, since your code will ALWAYS give your ItemTemplate the css
> class "plain" and AlternatingItemTemplate the css class "alter", why are
> you doing it in the codebehind at all? I would have done something like
> the following:
>
> <asp:Repeater ID="repSample" runat="server">
> <ItemTemplate>
> <asp:Label ID="lblItemContent" runat="server" Text="ItemTemplate Label"
> CssClass="plain"/>
> </ItemTemplate>
> <AlternatingItemTemplate>
> <asp:Label ID="lblAlternatingItemContent" runat="server"
> Text="AlternatingItemTemplate Label" CssClass="alter"/>
> </AlternatingItemTemplate>
> </asp:Repeater>
>
> I just used Labels as example content, but the point is that the styles
> are different in the two templates without the need for anything in the
> codebehind.
>
> As for your question about manipulating an item based on other items, I
> would suggest doing something that would involve the following:
>
> In the PreRender event, use the Items property of the Repeater to view and
> modify any items you wish to modify.
>
> Another approach that you could use would be to, in the ItemDataBound use
> the e.Item.ItemIndex property to get any necessary data from the
> Repeater's DataSource. To do this, you will use when getting the data from
> the Repeater's DataSource, you will do stuff like use e.Item.ItemIndex-1
> as the index to get data about the previous item or e.Item.ItemIndex+1 as
> the index to get the next item.
>
> Hopefully this helps. Because I have not seen your code and do not know
> what the goal of your project is, I cannot say whether or not there is
> another or better way, but when using databinding it is usually best to
> try to avoid basing the formatting of one item on another item. Good Luck!
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
> "K Viltersten" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>> One thing I would look into is using the AlternatingItemTemplate. This
>>> uses the same DataSource as the ItemTemplate, but it allows you to
>>> specify a different template.

>>
>> Well, that's what i'm using. Perhaps i should
>> clarify the code a bit more.
>>
>> ListItemType t = e.Item.ItemType;
>> if (t == ListItemType.AlternatingItem)
>> css += "alter";
>> else if (t == ListItemType.Item)
>> css += "plain";
>>
>>> You may want to look into the ItemDataBound event for this, and set the
>>> desired CSS from inside the ItemDataBound event...

>>
>> The setup above IS ALREADY in the event handler for data binding. Where
>> else could
>> it be placed, anyway?
>>
>> So, the question is, as i expressed it in my
>> original question, how one can manipulate the list item type of a given
>> item, depending
>> on the outcome of their predecessors and successors.
>>
>> Thank you.
>>
>> --
>>
>> Regards
>> Konrad Viltersten
>> --------------------------------
>> May all spammers die an agonizing death;
>> have no burial places; their souls be
>> chased by demons in Gehenna from one room
>> to another for all eternity and beyond.

>
>


 
Reply With Quote
 
musosdev
Guest
Posts: n/a
 
      10-05-2009
This might be way off, but could you not create a DataSet that's generated
from your data + a Hidden flag, and then DataBind from that, so the only
things that get sent to the Repeater are the actual things you want to show?

I'm not sure of the code to do it off-hand, but that's how I'd approach it.

"K Viltersten" wrote:

> As i mentioned in the original post, some of
> the rows will be hidden (regardless of them
> being styled to plain/alter.
>
> So, by only adding the style the way you
> described, i might get to SEE only plain
> rows (if the alternating happen to be hidden
> because of the new conditions).
>
> Index will not work either, for the same
> reason.
>
> I went for boolean flag that changes the
> state for each data bind event fired, except
> for those that are hidden. I'm not very
> satisfied with that solution, though.
>
> Any suggestion to that?
>
> Thanks.
>
> --
> Regards
> K Viltersten
> ----------------------------------------
> May all spammers die an agonizing death;
> have no burial places; their souls be
> chased by demons in Gehenna from one room
> to another for all eternity and beyond.
>
>
>
>
>
> "Nathan Sokalski" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > First of all, since your code will ALWAYS give your ItemTemplate the css
> > class "plain" and AlternatingItemTemplate the css class "alter", why are
> > you doing it in the codebehind at all? I would have done something like
> > the following:
> >
> > <asp:Repeater ID="repSample" runat="server">
> > <ItemTemplate>
> > <asp:Label ID="lblItemContent" runat="server" Text="ItemTemplate Label"
> > CssClass="plain"/>
> > </ItemTemplate>
> > <AlternatingItemTemplate>
> > <asp:Label ID="lblAlternatingItemContent" runat="server"
> > Text="AlternatingItemTemplate Label" CssClass="alter"/>
> > </AlternatingItemTemplate>
> > </asp:Repeater>
> >
> > I just used Labels as example content, but the point is that the styles
> > are different in the two templates without the need for anything in the
> > codebehind.
> >
> > As for your question about manipulating an item based on other items, I
> > would suggest doing something that would involve the following:
> >
> > In the PreRender event, use the Items property of the Repeater to view and
> > modify any items you wish to modify.
> >
> > Another approach that you could use would be to, in the ItemDataBound use
> > the e.Item.ItemIndex property to get any necessary data from the
> > Repeater's DataSource. To do this, you will use when getting the data from
> > the Repeater's DataSource, you will do stuff like use e.Item.ItemIndex-1
> > as the index to get data about the previous item or e.Item.ItemIndex+1 as
> > the index to get the next item.
> >
> > Hopefully this helps. Because I have not seen your code and do not know
> > what the goal of your project is, I cannot say whether or not there is
> > another or better way, but when using databinding it is usually best to
> > try to avoid basing the formatting of one item on another item. Good Luck!
> > --
> > Nathan Sokalski
> > (E-Mail Removed)
> > http://www.nathansokalski.com/
> >
> > "K Viltersten" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >>> One thing I would look into is using the AlternatingItemTemplate. This
> >>> uses the same DataSource as the ItemTemplate, but it allows you to
> >>> specify a different template.
> >>
> >> Well, that's what i'm using. Perhaps i should
> >> clarify the code a bit more.
> >>
> >> ListItemType t = e.Item.ItemType;
> >> if (t == ListItemType.AlternatingItem)
> >> css += "alter";
> >> else if (t == ListItemType.Item)
> >> css += "plain";
> >>
> >>> You may want to look into the ItemDataBound event for this, and set the
> >>> desired CSS from inside the ItemDataBound event...
> >>
> >> The setup above IS ALREADY in the event handler for data binding. Where
> >> else could
> >> it be placed, anyway?
> >>
> >> So, the question is, as i expressed it in my
> >> original question, how one can manipulate the list item type of a given
> >> item, depending
> >> on the outcome of their predecessors and successors.
> >>
> >> Thank you.
> >>
> >> --
> >>
> >> Regards
> >> Konrad Viltersten
> >> --------------------------------
> >> May all spammers die an agonizing death;
> >> have no burial places; their souls be
> >> chased by demons in Gehenna from one room
> >> to another for all eternity and beyond.

> >
> >

>
>

 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-05-2009
What CSS are you adding to the items to specify whether they are hidden or
not? Regardless of what other styling there is, if you set the CSS display
property to none, then it should be hidden. But here is a question that I
just want to make sure I have a clear answer on right now: Is your problem
in finding/accessing the items you want to modify, or is the problem in
figuring out how to style them to get a final product that looks the way you
want? I think it might be useful to everyone here in the newsgroup (at least
I would find it useful) if you showed us a little more code, as well as a
sample of what you want the final output to look like. Good Luck!
--
Nathan Sokalski
(E-Mail Removed)
http://www.nathansokalski.com/

"K Viltersten" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> As i mentioned in the original post, some of
> the rows will be hidden (regardless of them
> being styled to plain/alter.
>
> So, by only adding the style the way you
> described, i might get to SEE only plain
> rows (if the alternating happen to be hidden
> because of the new conditions).
>
> Index will not work either, for the same
> reason.
>
> I went for boolean flag that changes the
> state for each data bind event fired, except
> for those that are hidden. I'm not very
> satisfied with that solution, though.
>
> Any suggestion to that?
>
> Thanks.
>
> --
> Regards
> K Viltersten
> ----------------------------------------
> May all spammers die an agonizing death;
> have no burial places; their souls be
> chased by demons in Gehenna from one room
> to another for all eternity and beyond.
>
>
>
>
>
> "Nathan Sokalski" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> First of all, since your code will ALWAYS give your ItemTemplate the css
>> class "plain" and AlternatingItemTemplate the css class "alter", why are
>> you doing it in the codebehind at all? I would have done something like
>> the following:
>>
>> <asp:Repeater ID="repSample" runat="server">
>> <ItemTemplate>
>> <asp:Label ID="lblItemContent" runat="server" Text="ItemTemplate Label"
>> CssClass="plain"/>
>> </ItemTemplate>
>> <AlternatingItemTemplate>
>> <asp:Label ID="lblAlternatingItemContent" runat="server"
>> Text="AlternatingItemTemplate Label" CssClass="alter"/>
>> </AlternatingItemTemplate>
>> </asp:Repeater>
>>
>> I just used Labels as example content, but the point is that the styles
>> are different in the two templates without the need for anything in the
>> codebehind.
>>
>> As for your question about manipulating an item based on other items, I
>> would suggest doing something that would involve the following:
>>
>> In the PreRender event, use the Items property of the Repeater to view
>> and modify any items you wish to modify.
>>
>> Another approach that you could use would be to, in the ItemDataBound use
>> the e.Item.ItemIndex property to get any necessary data from the
>> Repeater's DataSource. To do this, you will use when getting the data
>> from the Repeater's DataSource, you will do stuff like use
>> e.Item.ItemIndex-1 as the index to get data about the previous item or
>> e.Item.ItemIndex+1 as the index to get the next item.
>>
>> Hopefully this helps. Because I have not seen your code and do not know
>> what the goal of your project is, I cannot say whether or not there is
>> another or better way, but when using databinding it is usually best to
>> try to avoid basing the formatting of one item on another item. Good
>> Luck!
>> --
>> Nathan Sokalski
>> (E-Mail Removed)
>> http://www.nathansokalski.com/
>>
>> "K Viltersten" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>> One thing I would look into is using the AlternatingItemTemplate. This
>>>> uses the same DataSource as the ItemTemplate, but it allows you to
>>>> specify a different template.
>>>
>>> Well, that's what i'm using. Perhaps i should
>>> clarify the code a bit more.
>>>
>>> ListItemType t = e.Item.ItemType;
>>> if (t == ListItemType.AlternatingItem)
>>> css += "alter";
>>> else if (t == ListItemType.Item)
>>> css += "plain";
>>>
>>>> You may want to look into the ItemDataBound event for this, and set the
>>>> desired CSS from inside the ItemDataBound event...
>>>
>>> The setup above IS ALREADY in the event handler for data binding. Where
>>> else could
>>> it be placed, anyway?
>>>
>>> So, the question is, as i expressed it in my
>>> original question, how one can manipulate the list item type of a given
>>> item, depending
>>> on the outcome of their predecessors and successors.
>>>
>>> Thank you.
>>>
>>> --
>>>
>>> Regards
>>> Konrad Viltersten
>>> --------------------------------
>>> May all spammers die an agonizing death;
>>> have no burial places; their souls be
>>> chased by demons in Gehenna from one room
>>> to another for all eternity and beyond.

>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling attachements hxbarney@cap.rr.com Firefox 2 12-02-2005 05:08 AM
Controlling Launch Access to the Browser Sam Firefox 0 04-23-2005 04:01 PM
Controlling Window position Daniel Prince Firefox 0 04-15-2005 04:51 PM
Controlling Internet Access on a Home Network =?Utf-8?B?d2lyZWxlc3NiZWdpbm5lcg==?= Wireless Networking 5 03-05-2005 11:32 PM
Automatically controlling where a file will be saved based on file extension and/or origin Daniel Prince Firefox 6 12-11-2004 10:58 PM



Advertisments