通過ItemDataBound事件操作資料控制元件中巢狀的其他控制元件
阿新 • • 發佈:2019-01-06
首先,需要在控制元件中宣告ItemDataBound事件。
其次,在code檔案中實現事件。
再次,程式碼示例如下。
<span style="font-size:14px;">protected void rptPhoto_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { LinkButton lblPRO = e.Item.FindControl("lbtnPro") as LinkButton; Label lbState = e.Item.FindControl("Label1") as Label; if (lbState.Text == "-1") { lblPRO.Visible = true; } } }</span>
protected void rptPhoto_ItemCommand(object sender, RepeaterCommandEventArgs e) { Literal litPhotoID = (Literal)e.Item.FindControl("litPhotoID"); Literal PhotoFilePathFlag = (Literal)e.Item.FindControl("PhotoFilePathFlag"); Literal PhotoFileName =(Literal)e.Item.FindControl("PhotoFileName"); int photoID = Convert.ToInt32(litPhotoID.Text); switch (((LinkButton)e.CommandSource).CommandName) { case "Pro": Response.Redirect("/manage/gallery/SaleAuditInfo.aspx?photoid=" + photoID + "&pname=" + PhotoFileName + "&pflag=" + PhotoFilePathFlag); break; case "Edit": Response.Redirect("/manage/gallery/ProductRelationModify.aspx?photoid=" + photoID); break; case"Content": Response.Redirect("/manage/gallery/ContentModify.aspx?photoid=" + photoID); break; case "Others": Response.Redirect("/manage/gallery/OtherContentModify.aspx?photoid=" + photoID); break; case "": break; } }
<ItemTemplate>
<td class="itemtd" style="width:200px;">
<asp:LinkButton ID="lbtnPro" runat="server" Text="稽核 |" CommandName="Pro" Visible="false"></asp:LinkButton>
<asp:LinkButton ID="lbtnEdit" runat="server" Text="修改類別 |" CommandName="Edit" Visible="false"></asp:LinkButton>
<asp:LinkButton ID="lbtnContent" CommandName="Content" runat="server">商品詳情 |</asp:LinkButton>
<asp:LinkButton ID="lbtnOthers" CommandName="Others" runat="server">其他</asp:LinkButton>
<asp:LinkButton ID="lbtnIsSale" CommandName="isSale" runat="server">上架</asp:LinkButton>
</td>
</tr>
</ItemTemplate>