Folks,
I'm seeing a really weird behavior, and for awhile I was sure I just did something dumb (okay, I probably still did something dumb) but I can't see it.
I have a dropdown at the head of a ListView that acts as a filter. When a user chooses a teacher name from the dropdown, the list needs to refresh and filter on that teacher's name. The whole module is in an UpdatePanel, and the dropdown is in a Placeholder control (I need to determine how to render the header of the list at runtime). I've tried removing both of those, and I still get the same result.
I need to capture that TeacherID from the dropdown on postback so I can instruct the ListView to return the right records. I do that in the "Selecting" event of the LINQ datasource bound to the listview (in my case, this is LDSTalks_Selecting). So what's the problem? In short, I don't get the "SelectedIndexChanged" event from the dropdown list, so I can't capture that new TeacherID.
If I databind the ListView on the postback, I DO get the SelectedIndexChanged event, but only after the LDSTalks_Selecting event, so it does me no good. This tells me I've at least wired the SelectedIndexChanged event properly. But if I don't databind the ListView on postback, I DON'T get the SelectedIndexChanged event. Any clues where to look? Ever seen this before?
Somehow I doubt this is a DNN thing, or no one else's modules would work ;-) Here's my source code edited down to only the relevant parts.
AldenG
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 ...
4
5 if (Page.IsPostBack)
6 {
7 // if I comment the following line out, I get no selecteditemchanged event from the dropdown list
8 LVTalks.DataBind();
9 }
10 }
11
12 protected void LDSTalks_Selecting(object sender, System.Web.UI.WebControls.LinqDataSourceSelectEventArgs e)
13 {
14 // select the right rows based on various factors,
15 // one of which is the TeacherID that should have been set
16 // from the selecteditemindex changed event
17 }
18
19 private void RenderTeacherList(int TeacherID)
20 {
21 DharmaTalksDataContext dc = new DharmaTalksDataContext();
22 DropDownList ddlTeachers = new DropDownList();
23 Literal litBy = new Literal();
24
25 ddlTeachers.Items.Add(new ListItem("All teachers", "0"));
26
27 /* get the teachers and sort them by last name */
28 var teach = from t in dc.SIMS_Teachers
29 orderby t.LastName
30 select t;
31
32 foreach (SIMS_Teacher tch in teach)
33 {
34 ddlTeachers.Items.Add(new ListItem(tch.FirstName + " " + tch.LastName, tch.TeacherID.ToString()));
35 }
36
37 if (TeacherID > 0)
38 ddlTeachers.Items.FindByValue(TeacherID.ToString()).Selected = true;
39
40 // add the dropdownlist to the placeholder control on the title
41 litBy.Text = "by ";
42 ddlTeachers.AutoPostBack = true;
43 ddlTeachers.Enableview_state = true;
44 ddlTeachers.SelectedIndexChanged += new EventHandler(ddlTeachers_SelectedIndexChanged);
45
46 ph.Controls.Add(litBy);
47 ph.Controls.Add(ddlTeachers);
48 }
49
50 // if i databind the listview, i receive this callback AFTER the LDSTalks_Selecting event,
51 // which does me no good. if I don't databind the listview, i don't receive it at all
52
53 void ddlTeachers_SelectedIndexChanged(object sender, EventArgs e)
54 {
55 DropDownList ddl = (DropDownList)sender;
56
57 TeacherID = Convert.ToInt32(ddl.SelectedValue);
58 }
And the form looks like this:
1 <asp:UpdatePanel ID="upAjax" runat="server">
2 <ContentTemplate>
3
4 <h2>Latest Talks <asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
5 </h2>
6 <asp:ListView ID="LVTalks" runat="server" DataKeyNames="TalkID"
7 DataSourceID="LDSTalks">
8 ... left out the listview...
9 </asp:ListView>
10
11 <asp:LinkButton ID="LBAddTalk" runat="server" onclick="LBAddTalkClicked">Add a talk</asp:LinkButton>
12
13 </ContentTemplate>
14 </asp:UpdatePanel>