Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 DLHell

Author  Topic 

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2006-09-06 : 10:02:42
I am having great trouble getting to grips with DataLists with ASP.NET 1.1. I think they are the best tool I have available to do what I need to but am really struggling to get them to do what I think they should do. Can anyone please point me in the direction of some good tutorials?

In case I have missed something really obvious (which is quite likely) here is what I have done so far

Just to play around and see how they worked I setup a simple one. Here is the ASP



<asp:datalist id="dlClinOutcome" runat="server" GridLines="Both" Caption="DataList" ShowHeader="False">
<EditItemStyle Wrap="False" BackColor="HotPink"></EditItemStyle>
<SelectedItemTemplate>
<asp:LinkButton id="LinkButton1" runat="server" CommandName="edit">Edit</asp:LinkButton>
</SelectedItemTemplate>
<AlternatingItemStyle Wrap="False"></AlternatingItemStyle>
<SeparatorStyle BorderColor="Red"></SeparatorStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:LinkButton id="hlnkSelect" runat="server" CommandName="select">Select</asp:LinkButton>
<asp:LinkButton id="LinkButton4" runat="server" CommandName="edit">Edit</asp:LinkButton>
</ItemTemplate>
<SeparatorTemplate>
<hr>
</SeparatorTemplate>
<EditItemTemplate>
<asp:LinkButton id="LinkButton2" runat="server">LinkButton</asp:LinkButton>
<asp:LinkButton id="LinkButton3" runat="server">LinkButton</asp:LinkButton>
</EditItemTemplate>
</asp:datalist>
Essentially a select link to select an item and an edit link to edit an item. Nothing too fancy there

For the code I have

    Private Sub dlClinOutcome_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlClinOutcome.ItemCommand
Dim cmd As String = e.CommandSource.CommandName
If cmd = "select" Then
Me.dlClinOutcome.SelectedIndex = e.Item.ItemIndex
ElseIf cmd = "quit" Then
Me.dlClinOutcome.SelectedIndex = -1
ElseIf cmd = "edit" Then
Me.dlClinOutcome.EditItemIndex = e.Item.ItemIndex
End If

End Sub



Again nothing fancy, select causes the item to be selected and edit causes it to be edited. However, I have discovered that I have to click a link twice to get it to do what I want, so if I want to edit I have to click the edit link twice and the same for Select. What's more the first click seems to be ignored as if I click one link then the other, only the second click is activated so if I click Select once then Edit once it goes to edit mode.



I'm convinced I've missed something very simple but have no idea what. Anyone have any clues?



thanks



steve


-----------

Don't worry head. The computer will do all the thinking from now on.

dfiala
Posting Yak Master

116 Posts

Posted - 2006-09-06 : 10:10:23
You need to rebind the list after setting the item index of choice

Private Sub dlClinOutcome_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlClinOutcome.ItemCommand
Dim cmd As String = e.CommandSource.CommandName
If cmd = "select" Then
Me.dlClinOutcome.SelectedIndex = e.Item.ItemIndex
ElseIf cmd = "quit" Then
Me.dlClinOutcome.SelectedIndex = -1
ElseIf cmd = "edit" Then
Me.dlClinOutcome.EditItemIndex = e.Item.ItemIndex
End If
'''Call method that rebinds the list!!!
End Sub

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2006-09-06 : 10:27:16
D'Oh, many thanks Dean once again. Shall I send you lots of virtual beer tokens!!

steve

-----------

Don't worry head. The computer will do all the thinking from now on.
Go to Top of Page
   

- Advertisement -