problems with selection in DataList web control

K

Konrad R.

Hi all

i want to create datalist, in which user selects and
deselects rows using the same LinkButton

so what i did, was checking, whether just selected
itemindex is the same as old one, if so, setting
selectedindex to -1 :

Protected Sub dlRoles_SelIdxChanges(ByVal sender As
Object, ByVal args As EventArgs) Handles
dlRoles.SelectedIndexChanged
If LastSelectedIndex = dlRoles.SelectedIndex Then
dlRoles.SelectedIndex = -1
LastSelectedIndex = -1
Else
LastSelectedIndex = dlRoles.SelectedIndex
End If
End Sub

where dlRoles is DataList with LinkButton (CommandName =
select) and LastSelectedIndex is property which holds
lastselectedindex in viewstate

when i first click 'select' button, frmwk executes
dlRoles_SelIdxChanges, but uses ItemTemplate, second time
i click select button, it does not execute
dlRoles_SelIdxChanges, but after roundtrip i see
SelectedItemTemplate used (after 2 clicks, not 1), next
when i click select button, dlRoles_SelIdxChanges is
executed, but still SelectedItemTemplate is used, 4-th
time i click select button, dlRoles_SelIdxChanges is not
executed, but ItemTemplate is used. Summarizing, normally
it would be 2 click (notselected->selected), in my case it
is 4 clicks (notselected-handler->notselected->selected-
handler->selected

where handler means execution of my handler
(dlRoles_SelIdxChanges)

additionally, when i do not click same row, but
consecutive rows, selected item seems to be 'one step
behind' of my clicks ....

any help ??

additionally pasting datalist def :


<asp:DataList ID="dlRoles" Runat="server">
<HeaderStyle BackColor="#99ffff"></HeaderStyle>
<HeaderTemplate>
<thead>
<td>lblNazwa</td>
<td>lblOrg.</td>
<td>lblUkr.</td>
<td>lblInfo</td>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval
(Container.DataItem, "RoleName") %>
</td>
<td>
<asp:LinkButton
runat="server" CommandName='<%# DataBinder.Eval
(Container.DataItem, "RoleName") %>' Text="ShowInfo" >
</asp:LinkButton>
</td>
<td>
<asp:LinkButton
Runat="server" CommandName="Select" text="Select"
ID="LinkbuttonA"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr bgcolor="#6600cc">
<td>
<%# DataBinder.Eval
(Container.DataItem, "RoleName") %>
</td>
<td>
<asp:LinkButton
runat="server" CommandName='<%# DataBinder.Eval
(Container.DataItem, "RoleName") %>' Text="ShowInfo"
ID="Linkbutton1" NAME="Linkbutton1">
</asp:LinkButton>
</td>
<td>
<asp:LinkButton
Runat="server" CommandName="Select" text="Select"
ID="Linkbutton2"></asp:LinkButton>
</td>
</tr>
</SelectedItemTemplate>
</asp:DataList>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top