首页 > 开发 > 综合 > 正文

Finding a Control Inside a Template

2024-07-21 02:16:46
字体:
来源:转载
供稿:网友
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>

<html>

<script language="c#" runat="server">

    void page_load(object src, eventargs e ) {

        if (!page.ispostback) {

            sqlconnection myconnection = new sqlconnection("server=(local)//netsdk;database=pubs;trusted_connection=yes");
            sqldataadapter mycommand = new sqldataadapter("select * from titles where type='business'", myconnection);

            dataset ds = new dataset();
            mycommand.fill(ds, "titles");

            mydatalist.datasource = ds.tables["titles"].defaultview;
            mydatalist.databind();
        }
    }

    void submit_click(object src, eventargs e ) {

          for (int i=0; i<mydatalist.items.count; i++) {

              string ischecked = ((checkbox) mydatalist.items[i].findcontrol("save")).checked.tostring();
              message.innerhtml += "item(" + i + "): " + ischecked + "<br>";
          }
    }

</script>

<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">

  <form runat="server">

  <!-- #include virtual="/quickstart/aspplus/samples/webforms/customize/header.inc" -->

  <asp:datalist id="mydatalist" repeatcolumns="2" runat="server">

      <itemtemplate>

        <table cellpadding=10 style="font: 10pt verdana">
          <tr>
            <td width=1 bgcolor="bd8672"/>
            <td valign="top">
              <img align="top" src='<%# databinder.eval(container.dataitem, "title_id", "/quickstart/aspplus/images/title-{0}.gif") %>' >
            </td>
            <td valign="top">
              <b>title: </b><%# databinder.eval(container.dataitem, "title") %><br>
              <b>category: </b><%# databinder.eval(container.dataitem, "type") %><br>
              <b>publisher id: </b><%# databinder.eval(container.dataitem, "pub_id") %><br>
              <b>price: </b><%# databinder.eval(container.dataitem, "price", "$ {0}") %>
              <p>
              <asp:checkbox id="save" runat="server"/> <b>save to favorites</b>
            </td>
          </tr>
        </table>

      </itemtemplate>

  </asp:datalist>

  <p>

  <div style="padding:0,15,0,15">
      <input type="submit" value="update favorites" onserverclick="submit_click" runat="server"/>
  </div>

  <p>

  <!-- #include virtual="/quickstart/aspplus/samples/webforms/customize/footer.inc" -->

  </form>

  <div style="font: 10pt verdana" enableviewstate="false" id="message" runat="server"/>

</body>
</html>

  
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表