我的Web表单应用程序的updatepanel中有一个数据列表,该数据列表包含:{图像按钮,标签,标签}。数据列表已连接到银行。在imagebutton中将显示图像的缩略图。我希望当用户单击数据列表中的每个图像按钮时,将显示原始图像。所有数据已成功显示在数据列表中,但问题是单击图像按钮后出现的。我不能继续。如何检测单击了哪个图像按钮?它的数据源是什么?同一单元格中标签的文本或数据源是什么?
请帮助我,我的代码很受打击:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="content">
<div class="datashow">
<asp:DataList ID="DataList1" runat="server" BorderColor="#666666" BorderStyle="None" BorderWidth="2px" CellPadding="2" CellSpacing="2" Font-Size="Small" RepeatDirection="Horizontal" CssClass="dl" HorizontalAlign="Center" RepeatColumns="5">
<HeaderStyle BackColor="#333333" Font-Bold="True" Font-Size="Large" ForeColor="White" HorizontalAlign="Center" Wrap="True" />
<ItemTemplate>
<asp:ImageButton ID="imgbtn" runat="server" ImageUrl='<%# Bind("imgtp","~/images/{0}") %>' Width="100px" OnClick="imgbtn_Click" />
<br />
<b>Employee Name:</b>
<asp:Label ID="lblCName" runat="server" Text='<%# Bind("name") %>'></asp:Label>
<br />
<b>Designation:</b>
<asp:Label ID="lblName" runat="server" Text='<%# Bind("company") %>'></asp:Label>
</ItemTemplate>
</asp:DataList>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
和
protected void imgbtn_Click(object sender, ImageClickEventArgs e)
{
//how to detect which imagebtn clicked and what is its datasource?
}
该sender
是按钮,它NamingContainer
是DataListItem
:
protected void imgbtn_Click(object sender, ImageClickEventArgs e)
{
var imgbtn = (ImageButton) sender;
var item = (DataListItem) imgbtn.NamingContainer;
// the datasource is not available on postback, but you have all other controls
var lblCName = (Label) item.FindControl("lblCName");
string company = lblCName.Text;
}
你也可以使用ImageButton
的CommandArgument
存储ID或使用一个隐藏的控制(Visible=false
或HiddenField
)储存。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句