标题:DataList取某个单元格的值没取到
只看楼主
a5015576
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-9-24
 问题点数:0 回复次数:2 
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);
       
    }

比如我点第一个单元格里的按钮,取到的是另一个单元格里的值,为啥会串行了呢?
搜索更多相关主题的帖子: border color 
2012-10-09 10:17
ttlj2012
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-10-14
得分:0 
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
改成 <asp:Button ID="Button2" runat="server" CommandArgument='<%#Bind("telno") %>' OnClick="Button2_Click" Text="Button"  />

后台:
    protected void Button2_Click(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
       string str = ();
        Response.Write(str);

    }
2012-10-17 17:28
zhuwj
Rank: 2
来 自:江苏
等 级:论坛游民
威 望:1
帖 子:63
专家分:58
注 册:2010-11-18
得分:0 
程序代码:
楼上说的对
修改:<asp:Button ID="Button2" CommandArgument='<%# Bind("telnoID") %>' runat="server" OnClick="Button2_Click" Text="Button" />


protected void Button2_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < DataList1.Items.Count; i++)
        {
           string str = ((Button)sender).CommandArgument.ToString();      
        }
        Response.Write(str);
      
    }
2012-10-26 09:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-382759-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.152373 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved