当我点击删除按钮图像没有被选中所以我无法获得该图像的特定图像。 [英] When I Click On Delete Button The Image Is Not Getting Selected So I Can't Get The Particular Imageurl Of That Image.

查看:68
本文介绍了当我点击删除按钮图像没有被选中所以我无法获得该图像的特定图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了通过按钮删除单个图像文件的代码,我的按钮和图像处于Datalist控件中,当我点击删除按钮时图像没有被选中,所以我无法获得该图像的特定图像。



//这是我的设计页面代码..



< asp:DataList ID =ImageDataList runat =serverRepeatColumns =6OnItemDataBound =ImageDataList_ItemDataBound

OnItemCommand =ImageDataList_ItemCommand>

< itemtemplate>



class =detailItem>



< asp:ImageButton class = example-image-linkID =Image1runat =serverHeight =150pxWidth =150px/>




< asp:Button ID =btndeleterunat =serverText =DeleteOnClick =btndelete_Click/>











//我的代码背后代码



protected void ImageDataList_ItemDataBound(object sender,DataListItemEventArgs e)

{

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType .AlternatingItem)

{

((System.Web.UI.WebControls.ImageButton)e.Item.FindControl(Image1))。ImageUrl = e.Item。 DataItem.ToString();
}

}



protected void ImageDataList_ItemCommand(object source,DataListCommandEventArgs e)

{

ImageButton lnkval =(ImageButton)e.Item.FindControl(Image1);

string path = lnkval.ImageUrl; // lnkval.Text;

Session.Add(路径,路径);



}



protected void btndelete_Click(object sender,EventArgs e)

{

string imgpath =((System.Web.UI.WebControls.Button)ImageDataList.FindControl(btndelete) ).Text;

}

protected void lnkmouseclick_Click(object sender,EventArgs e)

{

// DirectoryInfo directoryInfo = new DirectoryInfo(imgpath);

// FileInfo [] fileInfo = directoryInfo.GetFiles();

// string fullpath = fileInfo [0] .Name;

// string filename = ImageDataLis t.FindControl(Image1)。ToString();

// if(filename!=)

// {

// string globalpath = Session [globalpath] as string;

// File.Delete(globalpath + filename);

//}

}



//我该怎么办,请你帮我。

解决方案

那里不需要 lnkmouseclick_Click 此处活动,



更改 btnDelete_click 此类活动,



 受保护  void  btndelete_Click(  object  sender,EventArgs e)
{
ImageButton img =(ImageButton)e.Item.FindControl( Image1);
string path = img.ImageUrl;

string globalpath = Session [ globalpath] as string ;
File.Delete(globalpath + / path);
}





试试这个并通知我......

一切顺利......


首先,尝试获取所单击行的行索引,然后尝试使用获得的索引访问该图像。


然后转到客户端事件,使用 javascript jquery 处理按钮点击事件并获取imageUrl并将其存储在某些隐藏字段 ...

i have created code for deleting single image file through button, my button and image is in Datalist control, and when i click on delete button the image is not getting selected so i can't get the particular imageurl of that image.

//this my design page code..

<asp:DataList ID="ImageDataList" runat="server" RepeatColumns="6" OnItemDataBound="ImageDataList_ItemDataBound"
OnItemCommand="ImageDataList_ItemCommand">
<itemtemplate>


class="detailItem">

<asp:ImageButton class="example-image-link" ID="Image1" runat="server" Height="150px" Width="150px"/>


<asp:Button ID="btndelete" runat="server" Text="Delete" OnClick="btndelete_Click"/>





//this my code behind code

protected void ImageDataList_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
((System.Web.UI.WebControls.ImageButton)e.Item.FindControl("Image1")).ImageUrl = e.Item.DataItem.ToString();
}
}

protected void ImageDataList_ItemCommand(object source, DataListCommandEventArgs e)
{
ImageButton lnkval = (ImageButton)e.Item.FindControl("Image1");
string path = lnkval.ImageUrl;// lnkval.Text;
Session.Add("path", path);

}

protected void btndelete_Click(object sender, EventArgs e)
{
string imgpath = ((System.Web.UI.WebControls.Button)ImageDataList.FindControl("btndelete")).Text;
}
protected void lnkmouseclick_Click(object sender, EventArgs e)
{
//DirectoryInfo directoryInfo = new DirectoryInfo(imgpath);
//FileInfo[] fileInfo = directoryInfo.GetFiles();
//string fullpath = fileInfo[0].Name;
//string filename = ImageDataList.FindControl("Image1").ToString();
//if (filename != "")
//{
// string globalpath = Session["globalpath"] as string;
// File.Delete(globalpath + filename);
//}
}

// what should i do, can u help me please.

解决方案

There is no need of lnkmouseclick_Click Event here,

Change your btnDelete_click Eventlike this,

protected void btndelete_Click(object sender, EventArgs e)
   {
      ImageButton img = (ImageButton)e.Item.FindControl("Image1");
      string path = img.ImageUrl;

      string globalpath = Session["globalpath"] as string;
      File.Delete(globalpath+"/"path);
   }



try this and inform me...
All the best...


First, try to get the row index of the clicked row, and then try accessing the image by using the index obtained.


Then go for client side event, use javascript or jquery to handle button click event and get imageUrl and store it in some Hidden Field...


这篇关于当我点击删除按钮图像没有被选中所以我无法获得该图像的特定图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆