触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > Button读取DataList数据

Button读取DataList数据

前台:
<asp:DataList ID="DataList1" runat="server" Width="100%" CellPadding="0"  DataKeyField="id">
<ItemTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="20" width="10%" class="but" align="center" ><%# DataBinder.Eval(Container, "DataItem.post_date", "{0:d}")%></td>
<td height="20" width="10%" class="but" align="center" ><asp:Label ID="title" runat="server" Text='<%# Eval("title") %>'></asp:Label></td>
<td height="20" width="10%" class="but" align="left" ><asp:Label ID="content" runat="server" Text='<%#   DataBinder.Eval(Container.DataItem, "content").ToString().Replace("\r\n", "<br/>").Replace(" ", "&nbsp;&nbsp;")%>'></asp:Label></td>
<td height="20" width="5%" class="but" align="center" ><asp:Label ID="Amount1" runat="server" Text='<%#Eval("Amount")%>'></asp:Label></td>
<td height="20" width="5%" class="but" align="center" ><asp:Label ID="LabelA" runat="server" Text="Label"></asp:Label></td>
<td height="20" width="5%" class="but" align="center"><asp:Button ID="Button7"
        runat="server" onclick="Button7_Click" Text="修 改" /></td>
<td height="20" width="5%" class="but" align="center"><asp:CheckBox ID="CheckBox1" runat="server" /></td>
</tr>
</table>
</ItemTemplate>   
</asp:DataList>

后台:
    protected void Button7_Click(object sender, EventArgs e)
    {
        Button myButton = (Button)sender;
        int myIndex = ((DataListItem)myButton.NamingContainer).ItemIndex;//获得行号 
        int myId = Convert.ToInt16(DataList1.DataKeys[myIndex]);//获得id 
        Label title = (Label)this.DataList1.Items[myIndex].FindControl("title");
        Label Amount = (Label)this.DataList1.Items[myIndex].FindControl("Amount1");
        Label content = (Label)this.DataList1.Items[myIndex].FindControl("content");
        Response.Redirect("editExpenseapplication.aspx?number=" + number.Text + "&&dept=" + dept.Text + "&&name=" + name.Text + "&&title=" + title.Text + "&&username=" + username.Text + "&&post_date=" + post_date.Text + "&&Amount=" + Amount.Text + "&&content=" + content.Text + "&&id=" + myId + "");
    }


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com