Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Nichole Knight   on Jul 02 In Asp.net Category.

  
Question Answered By: Barachias Levi   on Jul 02

I have all the code (or so I think) froma previous site I made,
but that site (although working on the web) is in a bit of a mess on my hdd. My
most recent "test" prj I am even having trouble getting the edititem working
(1st attempt before I've even cleaned my teeth, straight out of bed so to
speak).

I'll get cleaned up and have another look ... will reply when sorted.

To tell the truth, there shouldn't be a problem, edit  mode has more
functionality than item  mode anyway, selecting a preconcieved value from a combo
isn't going to be an issue (I'm sure).
You just have to make sure you pull your existing values froma db and set  the
combos accordingly.

Hang on, are you using ItemDataBound ??? or are you using the datasource = '<%
..... %>' method ???

Note :: don't use this as even if you use a helper function like datasource =
'<%= getSrc() %>' you cannot give it the "DataListItemEventArgs e" that you need
to get to the controls within. So if you are in the designer then GET OUT of
there !! It's restrictive.

Do this ::


<asp:datalist id=DataList1 runat="server" DataKeyField="Manufacturer"
OnItemCreated="Item_Created" OnItemDataBound="List_ItemDataBound"
OnEditCommand="List_Edit" OnSelectCommand="List_Select"
OnSelectedIndexChanged="List_Select">

Then one of your buttons puts you in edit mode

public void List_ItemDataBound(Object sender, DataListItemEventArgs e)
{
.... here set your data source .... and because you have "DataListItemEventArgs
e" coming in you can also use e.Item and get to your controls using

FindControl()

ListItemType itemType = e.Item.ItemType;
if(itemType == ListItemType.EditItem){ }

if (itemType == ListItemType.AlternatingItem || itemType == ListItemType.Item){}

if(itemType == ListItemType.Footer){ }

}

So then you can set your combos to values that you will probably pull from
database.

Phil ... and anyone on this thread .... I have had to go "back in time" to find
and recap this (no probs), just soz I even suggested the datasource = '<% .....
%>' method in the first place.

NOTE :: This only works in EDIT mode, if you try to stick combos into Item mode
you will find you can fill them but cannot get to their eventhandlers - and so
cannot fire he "row selected  or datalist  row selected" event to do anything
with it.

The reason is that List_Select looks like this
public void List_Select(Object sender, EventArgs e) { } which DOESN'T give you
the "DataListItemEventArgs e", nor the e.Item you need to use FindControl()

There are "fudges" around, I (yesterday) made one .... but it's not up to much.
I can actually get the actual control using FindControl in "List_Select" (by
usng the control collection of the repeater ... thus avoiding the need for
e.Item) and then trying to assign and event handler to the individual control.
.... but still no way.

I haven't given up on that one yet (not quite) but basically asp.NET says "we
don't care what you try you an't using an event handler on a combo in a
repeater".

This will lead me to my next weak point which is Events and Delagates .... I'll
use this problem  as driving force to seewhat I can do with the attchment of that
handler to the combo.

Share: 

 

This Question has 8 more answer(s). View Complete Question Thread

 


Tagged: