autopostback problem listbox asp.net
Posted
by lodun
on Stack Overflow
See other posts from Stack Overflow
or by lodun
Published on 2010-05-09T16:54:18Z
Indexed on
2010/05/09
16:58 UTC
Read the original article
Hit count: 380
ASP.NET
I want to add posts(question) like i do that on yahoo answers.When i choose item in "kategorije" control,items can't be loaded in "SUB_kategorije" control.
My new ascx.cs:
1. protected void Page_Load(object sender, EventArgs e)
2. {
3.
4.
5. if (!Page.IsPostBack)
6. {
7.
8. SqlDataSource ds = new SqlDataSource();
9. ds.ConnectionString = conn;
10. ds.SelectCommand = "SELECT [ID], [Kategorije] FROM [kategorije] ";
11. kategorije.DataSource = ds;
12. kategorije.DataTextField = "Kategorije";
13. kategorije.DataValueField = "ID";
14. kategorije.DataBind();
15. kategorije.SelectedIndex = 1;
16.
17. SqlDataSource dk = new SqlDataSource();
18. dk.ConnectionString = conn;
19. dk.SelectCommand = "SELECT * from pod_kategorije WHERE kat_id = " + kategorije.SelectedItem.Value;
20. SUB_kategorije.DataSource = dk;
21. SUB_kategorije.DataTextField = "pkategorija";
22. SUB_kategorije.DataValueField = "ID";
23. SUB_kategorije.DataBind();
24.
25.
26. }
27.
28.
29.
30.
31. }
32. protected void kategorije_SelectedIndexChanged(object sender, EventArgs e)
33. {
34.
35.
36. SqlDataSource dk = new SqlDataSource();
37. dk.ConnectionString = conn;
38. dk.SelectCommand = "SELECT * from pod_kategorije WHERE [kat_id] = " + kategorije.SelectedItem.Value;
39. SUB_kategorije.DataSource = dk;
40. SUB_kategorije.DataTextField = "pkategorija";
41. SUB_kategorije.DataValueField = "ID";
42. SUB_kategorije.DataBind();
43.
44.
45. }
and .ascx:
1. <asp:ListBox ID="kategorije" runat="server" Height="380px" CssClass="kat" AutoPostBack="true"
2.
3. onselectedindexchanged="kategorije_SelectedIndexChanged"></asp:ListBox>
4.
5. <asp:Button ID="Button1" CssClass="posalji" runat="server" Text="click"
6. onclick="Button1_Click" />
7.
8.
9.
10. <asp:UpdatePanel ID="UpdatePanel10" runat="server">
11. <ContentTemplate> <asp:ListBox ID="SUB_kategorije" CssClass="pod" Height="150px" runat="server"></asp:ListBox></ContentTemplate>
12. <Triggers>
13. <asp:AsyncPostBackTrigger ControlID="kategorije" EventName="SelectedIndexChanged" />
14.
15. </Triggers>
16.
17. </asp:UpdatePanel>
© Stack Overflow or respective owner