469,299 Members | 2,065 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

repeater control with selection

Hi,
I wish to create a repeater control in c#.net that allows for the
selection of rows, any idea how this can be done.

Regards

Robert
Jun 27 '08 #1
5 3965
On May 30, 10:23*am, Robert Smith
<RobertSm...@discussions.microsoft.comwrote:
Hi,
* * *I wish to create a repeater control in c#.net that allows for the
selection of rows, any idea how this can be done.

Regards

Robert
why you want to use a repeater and not a grid for example?

what you mean with selection, you can use a checkbox column and when
checked you change the Css of the row, this is an indication of
"selection"
Jun 27 '08 #2
Hi Ignacio,
I wish to use a repeater because it is lighter than a gridview
and my supervisor recommended it.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
On May 30, 10:23 am, Robert Smith
<RobertSm...@discussions.microsoft.comwrote:
Hi,
I wish to create a repeater control in c#.net that allows for the
selection of rows, any idea how this can be done.

Regards

Robert

why you want to use a repeater and not a grid for example?

what you mean with selection, you can use a checkbox column and when
checked you change the Css of the row, this is an indication of
"selection"
Jun 27 '08 #3
A Gridview isn't always "lighter" or heavier that a Repeater; it depends
what you have in the control, how many rows and columns, and how many child
controls. Besides Gridview already has all the stuff you need, and since
your supervisor is asking you to reinvent the wheel by using a Repeater,
there's a pretty good chance he / /she is a real moron.
Peter

"Robert Smith" <Ro*********@discussions.microsoft.comwrote in message
news:7C**********************************@microsof t.com...
Hi Ignacio,
I wish to use a repeater because it is lighter than a gridview
and my supervisor recommended it.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
>On May 30, 10:23 am, Robert Smith
<RobertSm...@discussions.microsoft.comwrote:
Hi,
I wish to create a repeater control in c#.net that allows for the
selection of rows, any idea how this can be done.

Regards

Robert

why you want to use a repeater and not a grid for example?

what you mean with selection, you can use a checkbox column and when
checked you change the Css of the row, this is an indication of
"selection"
Jun 27 '08 #4
Hi,

I have a repeater control which is selectable, meaning that the selected row changes style on selection.
<asp:Repeater ID="repeaterList" runat="server" OnItemCommand="repeaterList_ItemCommand" OnItemDataBound="repeaterList_ItemDataBound">
<HeaderTemplate>
<table title="tableList" id="tableList" width="600px" style="font-size:small; font-family:Arial; border-style:solid; border-width:1px">
<tr style="background-color:#5D7B9D;color:White">
<th>Bill ID</th>
<th>Customer Name</th>
<th>Bill Number</th>
<th>Bill Date</th>
<th>Bill Total</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr title="trListRow" id="trListRow" class="tmpClass"
style="background-color:#F7F6F3; color:#333333"
onmouseover="javascript:setMouseOverColor(this);"
onmouseout="javascript:setMouseOutColor(this);"
onclick="javascript:setMouseClicked(this, <%# Container.ItemIndex %>);">
<td id="tdBillID"><%#DataBinder.Eval(Container.DataIte m, "BillID")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "CustomerName")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "BillNumber")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "BillDate")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "BillTotal") %></td>
<%--<td><asp:Button ID="click" Runat="server" CommandName="click" CommandArgument=<%# Container.ItemIndex %>></asp:Button></td>--%>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr id="trListRow" style="background-color:#FFFFFF; color:#284775"
onmouseover="javascript:setMouseOverColor(this);"
onmouseout="javascript:setMouseOutColor(this);"
onclick="javascript:setMouseClicked(this, <%# Container.ItemIndex %>);">
<td id="tdBillID"><%#DataBinder.Eval(Container.DataIte m, "BillID")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "CustomerName")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "BillNumber")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "BillDate")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "BillTotal") %></td>
</tr>

</AlternatingItemTemplate>

<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
and the Javascript functions changing style:
function setMouseOverColor(element)
{
oldgridSelectedColor = element.style.backgroundColor;
element.style.backgroundColor='#DEECEF';
element.style.cursor='hand';
}

function setMouseOutColor(element)
{
element.style.backgroundColor = oldgridSelectedColor;
element.style.textDecoration = 'none';
}

function setMouseClicked(element, index)
{
ResetTheTable(index);
oldgridSelectedColor = "#DEECEF";
}

function ResetTheTable(index)
{
var vTable = document.getElementById("tableList");
var vRows = vTable.getElementsByTagName("tr");

// we start from 1 because 0 is the header
for(i = 1; i < vRows.length; i++){
if(i%2)
{
vRows[i].style.backgroundColor = '#F7F6F3';
vRows[i].style.color = '#333333';
vRows[i].style.fontWeight = 'normal';
}
else
{
vRows[i].style.backgroundColor = '#FFFFFF';
vRows[i].style.color = '#284775';
vRows[i].style.fontWeight = 'normal';
}
}
vRows[index+1].style.backgroundColor = '#DEECEF';
vRows[index+1].style.color = '#333333';
vRows[index+1].style.fontWeight = 'bold';
}

This works very nicely, changing the style of the row when a row is selected.

What I would like help with is I don't know how to store th index of the selected row so I can later access it from my C# code. I am pretty new to ASP development, I tried storing the selection in <inputand <asp:Labelvariables but the values don't seem to be visible from the C# side.
Any help would be appreciated.

Thanks,
Blanka
Jun 27 '08 #5
Sorry, the declaration of the asp:Repeater got a bit trimmed on the last post. Basically in each TR I assign javascript functions for the onmouseover, onmouseout, onclick events (the stuff that didn't get trimmed). The reason there are 2 blocks of event assignments is that I use and ItemTemplate and an AlternatingItemTemplate in the repeater.

Sorry if I'm not very clear.

Thanks,
Blanka
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ShijuFrancis | last post: by
5 posts views Thread by Scott Lyon | last post: by
4 posts views Thread by MattB | last post: by
6 posts views Thread by Christoph Boget | last post: by
1 post views Thread by dinesh | last post: by
1 post views Thread by Christiaan Nieuwlaat | last post: by
2 posts views Thread by RichardH | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.