日期:2014-05-17 浏览次数:20528 次
<asp:DataList ID="DataList1" runat="server" RepeatColumns="6" RepeatDirection="Horizontal"> <ItemTemplate> <table border="0" cellpadding="5" bgcolor="#0010a4" align="center" cellspacing="1"> <tr> <td id="td2" runat="server" width="80" align="center" bgcolor="#6699ff"> <asp:Label ID="lbltel" Width="150px" runat="server" Text='<%# Bind("telno") %>'></asp:Label> </td> </tr> <tr> <td width="80" align="center" bgcolor="white"> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" /> </td> </tr> </table> </ItemTemplate> </asp:DataList>
string str; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { dbcom_src = db.GetSqlStringCommand("select telnoID,telno from M_TELNO where telnotrue=0"); db.ExecuteNonQuery(dbcom_src); DataList1.DataSource = db.ExecuteDataSet(dbcom_src).Tables[0]; DataList1.DataBind(); } } protected void Button2_Click(object sender, EventArgs e) { for (int i = 0; i < DataList1.Items.Count; i++) { str = ((Label)DataList1.Items[i].FindControl("lbltel")).Text; } Response.Write(str); }
<div> <asp:Button ID="Button1" runat="server" Text="Button" CommandArgument="<%#Bind('telno') %>" CommandName="" OnCommand="Button1_Command" /> </div>