我对EditItemTemplate有疑问 我在asp listView中使用Telerik RadUpload 在验证radUpload的事件时,我想检查一些需求,所以我需要findControl两个控件:radUpload和Label
为此我使用listView的ItemDataBound事件 但问题出在这里,首先执行ItemDataBound事件,然后执行RadUpload Validating事件,因此radUpload控件和Label控件保持为空
我通过使用静态控件来处理这个问题,但我认为这不是个好主意。
你有解决方案吗?
另一个问题是标签。但是,我使用静态标签并在跟踪显示标签有文本,但在输出标签中没有看到
<asp:ListView ID="LvAdminRing" runat="server" ItemPlaceholderID="ItemPlaceHolder" GroupPlaceholderID="GroupPlaceHolder"
OnItemEditing="LvAdminRing_ItemEditing" OnItemDataBound="onItemDataBound" OnItemUpdating="LvAdminRing_ItemUpdating">
<LayoutTemplate>
<div>
<asp:PlaceHolder runat="server" ID="GroupPlaceHolder"></asp:PlaceHolder>
</div>
</LayoutTemplate>
<GroupTemplate>
<div>
<asp:PlaceHolder runat="server" ID="ItemPlaceHolder"></asp:PlaceHolder>
</div>
</GroupTemplate>
<ItemTemplate>
<div class="RadRingTileDIV col-lg-12" runat="server">
<div class="row RadRingItemsDIV">
<asp:Label ID="lblPrice" CssClass="CustDispBlock CustItemFonts" runat="server" Text='<%# Eval("XPrice")%>'></asp:Label>
<asp:Label ID="lblCode" CssClass="CustDispBlock CustItemFonts" runat="server" Text='<%# Eval("XCode") %>'></asp:Label>
</div>
<div class="row RadRingItemsDIV ">
<asp:ImageButton ID="ImgRingEdit" runat="server" CommandName="Edit" ImageUrl="~/Image/Admin/CommandsPic/Edit.gif" />
<asp:ImageButton ID="ImgRingDel" runat="server" CommandName="Delete" ImageUrl="~/Image/Admin/CommandsPic/Delete.gif" />
</div>
</div>
</ItemTemplate>
<EditItemTemplate>
<div class="RadRingTileDIV col-lg-12" runat="server">
<div class="RadRingItemsDIV row">
<img src="ksdla" class="AdminImg CustDispBlock" />
<telerik:RadUpload ID="RupAdminRingPic" runat="server" AllowedFileExtensions=".png,.jpg,.jpeg,.jpe" AllowedMimeTypes="image/png,image/x-png,image/jpeg,image/pjpeg"
MaxFileInputsCount="1" MaxFileSize="52000" OverwriteExistingFiles="False" TargetFolder="~/Image/Products/Ring"
OnValidatingFile="RupAdminRingPic_ValidatingFile" ToolTip="انتخاب عکس جدید با پسوند های png،jpg،jpeg و jpe" ControlObjectsVisibility="CheckBoxes">
</telerik:RadUpload>
</div>
<div class="row RadRingItemsDIV">
<br />
<asp:Button ID="Button1" runat="server" Text="test" CommandName="Update" />
</div>
<div class="row RadRingItemsDIV">
<br />
<asp:Label ID="LblError" CssClass="CustDispBlock CustZ-Index" Visible="false" runat="server" Text=""></asp:Label>
</div>
</div>
</EditItemTemplate>
</asp:ListView>
public static Label lblError;
public static RadUpload RuEditPic;
public static Label lblError;
protected void RupAdminRingPic_ValidatingFile(object sender, Telerik.Web.UI.Upload.ValidateFileEventArgs e)
{
//Label test = (Label)LvItems.FindControl("LblError");
string[] AllowedFileExt = RuEditPic.AllowedFileExtensions;
foreach ( string AllowedExt in AllowedFileExt )
{
if (e.UploadedFile.ContentLength > RuEditPic.MaxFileSize)
{
lblError.Text = "some error";
lblError.Visible = true;
}
}
}
protected void onItemDataBound(object sender, ListViewItemEventArgs e)
{
int x = (e.Item as ListViewDataItem).DataItemIndex;
if (LvAdminRing.EditIndex == (e.Item as ListViewDataItem).DataItemIndex)
{
LvItems = LvAdminRing.Items as ListViewDataItem;
lblError = (e.Item.FindControl("LblError") as Label);
//errNoti = (e.Item.FindControl("LblError") as Label);
RuEditPic = (e.Item.FindControl("RupAdminRingPic") as RadUpload);
}
}
答案 0 :(得分:0)
你应该试试这个。
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
if (dataItem.DisplayIndex == ListView1.EditIndex)
{
TextBox tb = e.Item.FindControl("tbFK_MenuID") as TextBox;
}
}
}