DataList取某个单元格的值没取到
程序代码:
<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); }
比如我点第一个单元格里的按钮,取到的是另一个单元格里的值,为啥会串行了呢?