Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...