sj1187534 Posted April 17, 2004 Posted April 17, 2004 Hi...I am trying to implement edit information in-place in a datalist. I have an edit button for each item in a datalist and when the user clicks this button, the editing form opens up which should show the current information in its fields. Now, here's the problem. We can achieve this by using the <%# DataBinder.Eval(...) %> when loading the datalist. But what happens if we are loading the data from the ItemDataBound instead of the "DataBinder" thing. I mean...if you have a value from the datasource and we need to select the corresponding item in a dropdownlist in the editing form...what do you do? To understand more clearly, please take a look at the code I am working on: ========================================================= Private Sub dlSpecials_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlSpecials.ItemDataBound If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim dr As DataRow = Me.dlSpecials.DataSource.Table.Rows(e.Item.ItemIndex) ' ---------------------------------------------------- ' Load controls in the "EditItemTemplate" section ' ---------------------------------------------------- If e.Item.ItemIndex = Me.dlSpecials.EditItemIndex Then ' Recurrance criterion checkbox Dim chkrecur As CheckBox = CType(e.Item.FindControl("chkbRecurr"), CheckBox) If CBool(dr.Item("recurring")) = True Then chkrecur.Checked = True Else chkrecur.Checked = False End If ' Time Dim usctime1 As Time = CType(e.Item.FindControl("Time1"), Time) usctime1._Time = dr.Item("from_time").ToString().Split(" ")(0) usctime1._TimeSpan = dr.Item("from_time").ToString().Split(" ")(1) Else ' ---------------------------------------------------- ' Load controls in the "ItemTemplate" section ' ---------------------------------------------------- ' Time Dim lbtime As Label = CType(e.Item.FindControl("lblTime"), Label) lbtime.Text = dr.Item("from_time").ToString() & " to " & dr.Item("to_time").ToString() End If End If End Sub ========================================================= Thanks SJ Quote
sj1187534 Posted April 17, 2004 Author Posted April 17, 2004 Problem solved. I just needed to modify one small thing in this line: If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then to If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.EditItem Then Thats it. Thanks SJ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.