Datalist nested datalist (page binding background code using itemdatabound event for pure code)

Source: Internet
Author: User

  1. Project template directly pulls a radiobutton and then writes the JS Code as follows:

    <Script language = "JavaScript">
    Function check (radio ){
    VaR radiobuttons = Document. getelementsbytagname ("input ");
    For (VAR I = 0; I <radiobuttons. length; I ++ ){
    If (radiobuttons [I]. type = "radio "){
    If (radiobuttons [I] = radio ){
    Continue;
    }
    Else {
    Radiobuttons [I]. Checked = false;
    }

    }
    }
    }
    </SCRIPT>

    Source file:
    <Asp: datalist id = "datalist1" runat = "server">
    <Itemtemplate>
    <Asp: radiobutton id = "radiobutton1" onclick = "check (this)" runat = "server"/>
    </Itemtemplate>
    </ASP: datalist>

 

 

  1. <% @ Page Language = "C #" autoeventwireup = "true" codefile = "datalistnesting. aspx. cs" inherits = "datalistnesting" %>
  1. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  3. <Head runat = "server">
  4. <Title> datalistnesting </title>
  5. </Head>
  6. <Body>
  7. <Form ID = "form1" runat = "server">
  8. <Div>
  9. <Asp: datalist id = "datalist1" runat = "server" onitemdatabound = "datalist1_itemdatabound">
  10. <Itemtemplate>
  11. <Asp: Label id = "label1" runat = "server" text = '<% # eval ("orderid") %>'> </ASP: Label>
  12. <Asp: Label id = "label2" runat = "server" text = '<% # eval ("customerid") %>'> </ASP: Label>
  13. <Asp: datalist id = "datalist2" runat = "server">
  14. <Itemtemplate>
  15. <Asp: Label id = "label1" runat = "server" text = '<% # eval ("productid") %>'> </ASP: Label>
  16. <Asp: Label id = "label2" runat = "server" text = '<% # eval ("unitprice") %>'> </ASP: Label>
  17. <Asp: Label id = "label3" runat = "server" text = '<% # eval ("quantity") %>'> </ASP: Label>
  18. </Itemtemplate>
  19. </ASP: datalist>
  20. </Itemtemplate>
  21. </ASP: datalist>
  22. </Div>
  23. </Form>
  24. </Body>
  25. </Html>

Copy code

  1. Using system;
  2. Using system. Data;
  3. Using system. configuration;
  4. Using system. collections;
  5. Using system. Web;
  6. Using system. Web. Security;
  7. Using system. Web. UI;
  8. Using system. Web. UI. webcontrols;
  9. Using system. Web. UI. webcontrols. webparts;
  10. Using system. Web. UI. htmlcontrols;
  11. Using system. Data. sqlclient;
  12. Public partial class datalistnesting: system. Web. UI. Page
  13. {
  14. Private void bindlist ()
  15. {
  16. Sqlconnection Cn = new sqlconnection (@ "Server =. \ sqlexpress; uid = sa; Pwd =; database = northwind ");
  17. Sqldataadapter da = new sqldataadapter ("select orderid, customerid from orders", CN );
  18. Dataset DS = new dataset ();
  19. CN. open ();
  20. Da. Fill (DS );
  21. CN. Close ();
  22. Datalist1.datasource = Ds. Tables [0]. defaultview;
  23. Datalist1.datakeyfield = "orderid ";
  24. Datalist1.databind ();
  25. }
  26. Private void page_load (Object sender, system. eventargs E)
  27. {
  28. If (! Ispostback)
  29. {
  30. Bindlist ();
  31. }
  32. }
  33. Protected void datalist1_itemdatabound (Object sender, datalistitemeventargs E)
  34. {
  35. Datalist datalist2;
  36. If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
  37. {
  38. Datalist2 = E. Item. findcontrol ("datalist2") as datalist;
  39. If (datalist2! = NULL)
  40. {
  41. Sqlconnection Cn = new sqlconnection (@ "Server =. \ sqlexpress; uid = sa; Pwd =; database = northwind ;");
  42. Sqldataadapter da = new sqldataadapter ("select productid, unitprice, quantity from [Order Details] Where orderid = @ orderid", CN );
  43. Da. selectcommand. Parameters. addwithvalue ("@ orderid", (E. Item. dataitem as datarowview) ["orderid"]);
  44. Dataset DS = new dataset ();
  45. CN. open ();
  46. Da. Fill (DS );
  47. CN. Close ();
  48. Datalist2.datasource = Ds. Tables [0]. defaultview;
  49. Datalist2.databind ();
  50. }
  51. }
  52. }
  53. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.