Basically the question is:
how do i get the ImageID from a repeater so that i can pass it with a query string on button click?
For example: i need to edit a Image Details , each image have a edit button
As shown below:( generated by repeater)
c# code:
var List = new List<Images>();
foreach (DataRow dr in picture.Rows)
{
DateTime DateTemp = DateTime.Parse(dr["date"].ToString());
var childPhoto = new Images()
{
DateTaken = DateTemp.ToString("MM/dd/yyyy"),
PlaceTaken = dr["place"].ToString(),
DetailedInfo = dr["info"].ToString(),
ImageID = dr["ImageId"].ToString()
};
childList.Add(childPhoto);
}
ShowPhotoRepeater.DataSource = List;
ShowPhotoRepeater.DataBind();
}
}
}
protected void btnEditChildPhoto_Click(object sender, EventArgs e)
{
Response.Redirect("EditPhoto.aspx?ImageID=" + ));
}
My aspx code:
<asp:Repeater ID="ShowProfileRepeater" runat="server">
<ItemTemplate>
<table>
<tr>
<td width = "15%" rowspan="6"><%--<asp:Image ID="ImgPhoto" runat=server />--%>
<%--<asp:Image ID="childImage" ImageUrl="<%#Eval("ImgUrl")%>" runat="server" />--%>
<asp:Image ID="childImage" ImageUrl="~/img/missing children pictures/shearwey.jpg" CssClass="content_image" runat="server" />
</td><br />
<td width = "15%">Name:</td>
<td width = "70%">
<asp:Label ID="lblChildName" runat="server" Text='<%#Eval("Name")%>'></asp:Label></td>
<td >
<asp:Button ID="btnEditChildProfile" runat="server" Text="Edit" />
</td>
</tr>
<tr>
<td width = "15%">Gender:</td>
<td width = "55%">
<asp:Label ID="lblChildGender" runat="server" Text='<%#Eval("Gender")%>'></asp:Label></td>
<td></td>
</tr>
<tr>
<td width = "10%">Date Of Birth:</td>
<td width = "55%">
<asp:Label ID="lblChildDOB" runat="server" Text='<%#Eval("DOB")%>'></asp:Label></td>
<td></td>
</tr>
<tr>
<td width = "10%">Country:</td>
<td width = "55%">
<asp:Label ID="lblChildCountry" runat="server" Text='<%#Eval("Country")%>'></asp:Label></td>
<td></td>
</tr>
<tr>
<td width = "10%">Missing Date:</td>
<td width = "55%">
<asp:Label ID="lblChildMissingDt" runat="server" Text='<%#Eval("MissingDt")%>'></asp:Label></td>
<td></td>
</tr>
<tr>
<td width = "10%">Last Seen Location:</td>
<td width = "55%">
<asp:Label ID="lblChildLaseSeenLoc" runat="server" Text='<%#Eval("LastSeenLoc")%>'></asp:Label></td>
<td></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="btnEditChildProfile" runat="server" Text="Edit" CommandArgument='<%# Eval("ImageId")%>' />
protected void btnEditChildPhoto_Click(object sender, EventArgs e)
{
var btn = (Button)sender;
Response.Redirect("EditPhoto.aspx?ImageID=" + btn.CommandArgument));
}
Or
<a href='EditPhoto.aspx?ImageID=<%# Eval("ImageId") %>' >Edit</a>
Instead of using a button use a link button inside the repeater to redirect to the link you want. That way, you won't need a separate event handler for the button.
<asp:LinkButton PostBackUrl="EditPhoto.aspx?ImageID=<%#Eval("ImageId")%>"></asp:LinkButton>
Related
Typical listview.
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" OnSelectedIndexChanging="ListView1_SelectedIndexChanging"
OnSelectedIndexChanged="ListView1_SelectedIndexChanged">
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' />
</td>
<td>
<asp:Label ID="HotelNameLabel" runat="server" Text='<%# Eval("HotelName") %>' />
</td>
<td>
<asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
</td>
<td>
<asp:Button ID="cmdLstSel" runat="server" Text="View" CssClass="btn"
CommandName="Select"/>
</td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr style="" class="alert-info">
<td>
<asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' />
</td>
<td>
<asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' />
</td>
<td>
<asp:Label ID="HotelNameLabel" runat="server" Text='<%# Eval("HotelName") %>' />
</td>
<td>
<asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
</td>
<td>
<asp:Button ID="cmdLstSel" runat="server" Text="View" CssClass="btn" OnClick="cmdLstSel_Click" />
</td>
</tr>
</SelectedItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server">FirstName</th>
<th runat="server">LastName</th>
<th runat="server">HotelName</th>
<th runat="server">City</th>
<th runat="server">View</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
So we can highlight the row clicked with:
protected void ListView1_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
}
protected void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
GPayments.DataSource = MyRst("SELECT * FROM HotelPayments WHERE Hotel_ID = " + hID);
GPayments.DataBind();
}
Now if I leave out the re-bind, then of course the row will highlight, but of course it is the "previous" row that hight lights.
And if I could set the class of the ONE row, then I could dump the selected item template.
You can do this with GREAT ease in a GridView, and I often do this:
Dim gRow As GridViewRow = -- get any row
gRow.CssClass = " alert-info"
however, I would like to do the same with listView. When I do above for GridView, then I don't need or have to bother with a re-bind, and I don't even need a selected template either.
So left is a grid view, and we get this:
However, I want to do this with listview.
(and WITHOUT having to do a re-bind).
Any simple way to highlight a row in ListView WITHOUT a re-bind?
Ok, a bit of googling, and the solution becomes VERY easy.
The goal here is to click on a row - highlight that row.
Of course WAY too much work to have to include a selected row template.
It is a better trade off to add 3 lines of code to do this.
So, say we have this markup:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID"
OnSelectedIndexChanged="ListView1_SelectedIndexChanged" OnSelectedIndexChanging="ListView1_SelectedIndexChanging" >
<ItemTemplate>
<tr id="mytr" runat="server">
<td><asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' /></td>
<td><asp:Label ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' /></td>
<td><asp:Label ID="HotelNameLabel" runat="server" Text='<%# Eval("HotelName") %>' /></td>
<td><asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' /></td>
<td>
<asp:Button ID="cmdLstSel" runat="server" Text="View" CssClass="btn"
CommandName="Select" OnClick="cmdLstSel_Click"/>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" class="table table-hover" style="">
<tr runat="server" style="">
<th runat="server">FirstName</th>
<th runat="server">LastName</th>
<th runat="server">HotelName</th>
<th runat="server">City</th>
<th runat="server">View</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
ok, our code to fill is this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadView();
}
}
void LoadView()
{
ListView1.DataSource = MyRst("SELECT TOP 12 * FROM tblHotels ORDER BY HotelName");
ListView1.DataBind();
}
Output:
Ok, so for the row click? Well, we don't have to use the selected index changed, but, for this we will (so CommandName="Select" is what triggers that index changed event).
However, I want a simple button click, and with some code (to display the details part).
So, our button click is this:
protected void cmdLstSel_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
ListViewDataItem gRow = (ListViewDataItem)btn.Parent.Parent.Parent;
int hID = (int)ListView1.DataKeys[gRow.DisplayIndex]["ID"];
GHotelOptions.DataSource = MyRst("SELECT * FROM HotelOptions WHERE Hotel_ID = " + hID);
GHotelOptions.DataBind();
GPayments.DataSource = MyRst("SELECT * FROM HotelPayments WHERE Hotel_ID = " + hID);
GPayments.DataBind();
}
Above will fill the child tables. Note the cool trick to get the row - I don't bother with the listview event model!
Now for the row highlight.
The trick is to add an "id" to the tr row like this:
<ItemTemplate>
<tr id="mytr" runat="server">
So, we can now pick up the tr element.
So on lv index changed, we do this:
protected void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
ListViewItem gRow = (ListViewItem)ListView1.Items[ListView1.SelectedIndex];
if ( (ViewState["MySel"] != null) && ((int)ViewState["MySel"] != gRow.DataItemIndex) )
{
ListViewItem gLast = ListView1.Items[(int)ViewState["MySel"]];
HtmlTableRow hTRL = (HtmlTableRow)gLast.FindControl("mytr");
hTRL.Attributes.Add("class", "");
}
HtmlTableRow hTR = (HtmlTableRow)gRow.FindControl("mytr");
hTR.Attributes.Add("class", "alert-info");
ViewState["MySel"] = gRow.DataItemIndex;
}
So, I did use row state, but that lets me un-highlight + highlight, and I do NOT hve to re-bind the grid.
And I just picked a nice boot strap class - it even "reverses" the text - very nice.
So now we get this:
So this did cost about 4-5 extra lines. But, we trade that for NOT having a selected template in the lv (and that's too much to maintain both the row layout and THEN have to maintains the same for selected template. And worse, you STILL had to re-bind for the highlighted row click to show. This way, we don't.
I also used a "helper" routine to get a datatable, and that was this:
public DataTable MyRst(string strSQL)
{
DataTable rstData = new DataTable();
using (SqlCommand cmdSQL = new SqlCommand(strSQL,
new SqlConnection(Properties.Settings.Default.TEST3)))
{
cmdSQL.Connection.Open();
rstData.Load(cmdSQL.ExecuteReader());
}
return rstData;
}
At the end of the day, we can now highlight the row, do so with a click, and we could even move the selected index changed code to our button code and not even use the lv index and built in events.
I have below list view , how can i hide column by code behind ?
<asp:ListView ID="AuditLogListView" runat="server" OnItemCreated="AuditLogListView_ItemCreated">
<LayoutTemplate>
<table class="table table-striped table-bordered small">
<tr class="table-secondary">
<th id="BlockHeader" runat="server" style="white-space: normal;">
<asp:Literal ID="BlockHeaderLiteral" runat="server" Text="<%$ Resources:AppResources, AuditInformationBlockHeader %>" />
</th>
</tr>
<asp:PlaceHolder runat="server" ID="ItemPlaceholder"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td id="BlockStatus" runat="server">
<%# Eval("BlockStatus")%>
</td>
</tr>
</ItemTemplate>
After binding data with list view i tried below code behind but with this header text only hide but column still can still visible
if (groupOrBlockValue == 'W')
{
AuditLogListView.FindControl("BlockHeader").Visible = false;
AuditLogListView.FindControl("BlockHeaderLiteral").Visible = false;
//AuditLogListView.FindControl("BlockStatus").Visible = false;
}
Missing part of the list view?
With this:
<asp:ListView ID="LstMarks" runat="server" DataKeyNames="ID" >
<ItemTemplate>
<tr style="">
<td><asp:Textbox ID="Course" runat="server" Text='<%# Eval("Course") %>' /></td>
<td><asp:Textbox ID="Mark" runat="server" Text='<%# Eval("Mark") %>' Width="30px"/></td>
<td>
<asp:CheckBox ID="DoneLabs" runat="server" Checked = '<%# Eval("DoneLabs") %>' Width="30px"/>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="itemPlaceholderContainer" runat="server" border="0" class="table">
<tr runat="server" style="">
<th runat="server" >Course</th>
<th runat="server">Mark</th>
<th id= "LabW" runat="server" >Completed Lab Work</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<br />
<br />
<asp:Button ID="cmdHide" runat="server" Text="Hide Lab check box" OnClick="cmdHide_Click" />
So note in the layout, we added a "id" = LabW - that lets you hide the header.
so, a simple button that would toggle (hide/show) the lvColum, then this works:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlCommand cmdSQL = new SqlCommand("SELECT * from StudentCourses",
new SqlConnection(Properties.Settings.Default.TEST4)))
{
cmdSQL.Connection.Open();
LstMarks.DataSource = cmdSQL.ExecuteReader();
LstMarks.DataBind();
}
}
}
protected void cmdHide_Click(object sender, EventArgs e)
{
Control ctrHeader = LstMarks.FindControl("LabW");
ctrHeader.Visible = !ctrHeader.Visible;
foreach (ListViewItem lvRow in LstMarks.Items)
{
CheckBox ckBox = (CheckBox)lvRow.FindControl("DoneLabs");
ckBox.Visible = !ckBox.Visible;
}
}
So, we get this:
And clicking on the button, we get this:
And both the values changed - they persist - even when you click again (to toggle and show the hidden columns).
Edit: =====================================================
So, say this markup:
<asp:ListView ID="AuditLogListView" runat="server"
OnItemCreated="AuditLogListView_ItemCreated">
<LayoutTemplate>
<table class="table table-striped table-bordered small">
<tr class="table-secondary">
<th id="BlockHeader" runat="server" style="white-space: normal;">
<asp:Literal ID="BlockHeaderLiteral" runat="server" Text="Hotel Name" />
</th>
</tr>
<asp:PlaceHolder runat="server" ID="ItemPlaceholder"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td id="BlockStatus" runat="server">
<%# Eval("BlockStatus")%>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
And code behind button to hide is this:
protected void Button1_Click(object sender, EventArgs e)
{
Control ctrHeader = AuditLogListView.FindControl("BlockHeaderLiteral");
ctrHeader.Visible = !ctrHeader.Visible;
foreach (ListViewItem lvRow in AuditLogListView.Items)
{
Control BlockStat = (Control)lvRow.FindControl("BlockStatus");
BlockStat.Visible = !BlockStat.Visible;
}
}
At which event have you written this code?
Required this code in the OnDataBound event. And in your code this event missing.
<asp:ListView ID="AuditLogListView" runat="server" OnItemCreated="AuditLogListView_ItemCreated" OnDataBound="AuditLogListView_DataBound">
<asp:Literal ID="BlockHeaderLiteral" runat="server" Text="<%$ Resources:AppResources, AuditInformationBlockHeader %>" /><asp:PlaceHolder runat="server" ID="ItemPlaceholder"></asp:PlaceHolder>
C# Code:
protected void AuditLogListView_DataBound(object sender, EventArgs e)
{AuditLogListView.FindControl("BlockHeaderLiteral").Visible = false;}
image
The Upper portion of present my database table structure and lower portion that in which form i want to show data.
<table class="table table-bordered table-hover">
<thead>
<tr class="text-center">
<th>Course Code</th>
<th>Subject</th>
<th>Cr.Hours</th>
<th>Grade</th>
</tr>
<tr>
<td colspan="4">
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</thead>
<tbody>
<asp:Repeater ID="outer" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Label Text='<%#Eval("[SpringFall]")%>' Style="text-align: center; display: none; font-size: 18px; font-family: 'Times New Roman'" ID="Label4" runat="server" Font-Bold="true"> </asp:Label>
</td>
<td>
<asp:Label ID="AllCcode" runat="server" Text='<%#Eval("[Course_Code]") %>'></asp:Label>
</td>
<td>
<asp:Label ID="AllSubject" runat="server" Text='<%#Eval("[Subject]") %>'></asp:Label>
</td>
<td>
<asp:Label ID="AllCrHr" runat="server" Text='<%#Eval("[Credit_Hours]") %>'></asp:Label>
</td>
<td>
<asp:Label ID="AllGrade" Font-Bold="true" runat="server" Text='<%#Eval("[Total_Marks]") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
Here Is my code..bind repeater on button click event using c# with simple sql SELECT query.Any query for bind repeater with more efficient working and show data in given form.
protected void AttendencBtn_Click(object sender, EventArgs e)
{
// MultiView1.ActiveViewIndex = 8;
conn.Open();
sda = new SqlDataAdapter("SELECT * FROM Attendence where Roll_Number='" + Session["RollNumb"] + "' ", conn);
dt = new DataTable();
sda.Fill(dt);
AttendencRpt.DataSource = dt;
AttendencRpt.DataBind();
conn.Close();
}
I think you are looking for something like this. First create a public variable in code behind.
public int currentYear = 2000;
protected void Page_Load(object sender, EventArgs e)
{
}
Then change the Repeater to something like this:
<table border="1">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%# Convert.ToDateTime(Eval("myYear")).Year != currentYear && Container.ItemIndex > 0 ? "<tr><td colspan=\"5\">" + Eval("myYear") + "</td></tr>" : "" %>
<tr>
<td>
normal rows here
</td>
</tr>
<%# currentYear = Convert.ToDateTime(Eval("myYear")).Year %>
</ItemTemplate>
</asp:Repeater>
</table>
What will happen is that the value of currentYear is compared to the current row value. If it does not match a new row will be created. Then the value of currentYear is updated to be checked in the next row bound to the Repeater.
There is a ListView which shows the data that were retrieved from the database.
I want to edit a single record on a ListView by clicking the edit button beside it but if I press the edit button, I get the error:
The ListView 'lvItemView' raised event ItemEditing which wasn't handled.
Here is the ListView:
<asp:ListView ID="lvItemView" runat="server" ItemPlaceholderID="itemHolder">
<LayoutTemplate>
<table style="color: Black;" width="100%" border="0" cellpadding="5">
<tr>
<th style="text-align: center;">Customer ID</th>
<th style="text-align: center;">Contact Name</th>
<th style="text-align: center;">Company</th>
<th style="text-align: center;">Created By</th>
<th style="text-align: center;">Created Date</th>
<th style="text-align: center;">Modified By</th>
<th style="text-align: center;">Modified Date</th>
</tr>
<asp:PlaceHolder ID="itemHolder" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td align="left">
<asp:Label ID="lblCustomerID" runat="Server" Text='<%#Eval("_CustomerID") %>' />
</td>
<td align="left">
<asp:Label ID="lblContactName" runat="Server" Text='<%#Eval("_ContactName") %>' />
</td>
<td align="left">
<asp:Label ID="lblCompany" runat="Server" Text='<%#Eval("_CompanyID") %>' />
</td>
<td align="left">
<asp:Label ID="lblCreatedBy" runat="Server" Text='<%#Eval("_CreatedBy") %>' />
</td>
<td align="left">
<asp:Label ID="lblCreatedDate" runat="Server" Text='<%#Eval("_CreatedDate") %>' />
</td>
<td align="left">
<asp:Label ID="lblModifiedBy" runat="Server" Text='<%#Eval("_ModifiedBy") %>' />
</td>
<td align="left">
<asp:Label ID="lblModifiedDate" runat="Server" Text='<%#Eval("_ModifiedDate") %>' />
</td>
<td align="left">
<asp:LinkButton ID="EditButton" runat="Server" Text="Edit" CommandName="Edit" CommandArgument='<%#DataBinder.Eval(Container, "DataItemIndex")%>' />
</td>
<td align="left">
<asp:LinkButton ID="Delete" runat="Server" Text="Delete" CommandName="Delete" CommandArgument='<%#DataBinder.Eval(Container, "DataItemIndex")%>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
And the code behind
protected void lvItemView_ItemEditing(object sender, ListViewEditEventArgs e)
{
System.Web.UI.WebControls.Label index_id = (System.Web.UI.WebControls.Label)lvItemView.Items[e.NewEditIndex].FindControl("lblCustomerID");
int customerID = int.Parse(index_id.Text);
Item item = new Item();
item._CustomerID = customerID;
System.Web.UI.WebControls.Label cmp_id = (System.Web.UI.WebControls.Label)lvItemView.Items[e.NewEditIndex].FindControl("lblCompany");
int companyID = int.Parse(cmp_id.Text);
item._CompanyID = companyID;
System.Web.UI.WebControls.Label samp = (System.Web.UI.WebControls.Label)lvItemView.Items[e.NewEditIndex].FindControl("lblContactName");
item._ContactName = samp.Text;
samp = (System.Web.UI.WebControls.Label)lvItemView.Items[e.NewEditIndex].FindControl("lblCreatedBy");
item._CreatedBy = samp.Text;
samp = (System.Web.UI.WebControls.Label)lvItemView.Items[e.NewEditIndex].FindControl("lblCreatedDate");
item._CreatedDate = samp.Text;
samp = (System.Web.UI.WebControls.Label)lvItemView.Items[e.NewEditIndex].FindControl("lblModifiedBy");
item._ModifiedBy = samp.Text;
samp = (System.Web.UI.WebControls.Label)lvItemView.Items[e.NewEditIndex].FindControl("lblModifiedDate");
item._ModifiedDate = samp.Text;
CustomerID = item._CustomerID.ToString();
ContactName = item._ContactName.ToString();
CompanyID = item._CompanyID.ToString();
CreatedBy = item._CreatedBy.ToString();
CreatedDate = item._CreatedDate.ToString();
ModifiedBy = item._ModifiedBy.ToString();
ModifiedDate = item._ModifiedDate.ToString();
modAdd.Show();
}
I am new to asp.net and c# so I have no idea what to do with this kind of error.
set the event lvItemView_ItemEditing in OnItemEditing which will be triggered when click on edit button
<asp:ListView ID="lvItemView" runat="server" ItemPlaceholderID="itemHolder" OnItemEditing="lvItemView_ItemEditing">
and also set data source if you are binding on pageload
lvItemView.DataSource = SomeData;
lvItemView.DataBind();
i am creating a website, in asp.net and using C# my problem is i created a asp repeater which is working fine so i added a imagebutton to download the file that the repeater contains, but i cant get it to download that file, hope someone can help me out i have this already, i have tried a couple of ways but could get it to do what i wanted. here is my code.
ASP
<asp:Repeater ID="RepDetailsPost" runat="server" OnItemCommand="Save" >
<HeaderTemplate>
<table style="width:500px" align ="center" cellpadding="0" class="rounded_corners" >
<tr style="background-color:Red; color:White">
<td valign="top" bgcolor="CC0000" >
<b>Post</b>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#333">
<td>
<table style="background-color:#222; width:500px" class="rounded_corners" >
<table>
<tr>
<td style="font-size:large">
Utilizador:
<asp:Label ID="lblSubject0" runat="server" Text='<%#Eval("nome_utilizador") %>'
Font-Size="small" Font-Bold="true"/>
</td>
</tr>
</table>
</td>
</tr>
<tr style="background-color:#333;Color:White">
<td align="right" >
Criado em:<asp:Label ID="lblDate0" runat="server" Font-Bold="true"
Text='<%#Eval("data") %>'/>
</td>
</tr>
<tr>
<td>
<table style="background-color:#222; width:500px">
<tr>
<td>Anexo:
<asp:Image ImageUrl=<%# string.Format("~/uploads/{0}",Eval("Nome"))%> runat="server" width=500px/>
</td>
</tr>
</table>
<table style="background-color:#222; width:500px">
<tr>
<td>Guardar:
<asp:ImageButton ID="save" ImageUrl=<%# string.Format("~/imagens/icones/save.png")%> runat="server" width=30px CommandName="save"
CommandArgument='<%# Eval("Nome") %>' />
\\\\\\\\\\\\\\\ this is what I tried on top /////////////////
</tr>
</table>
<table style="background-color:#222; width:500px" align=center>
<tr>
<td>Comentário: <br /><asp:Label ID="lblComment0" Font-Size="small" runat="server" Text='<%#Eval("descricao") %>' /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"valign="top" bgcolor="CC0000">
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
C#
protected void Save(Object Sender, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Save")
{
int index = Convert.ToInt32(e.CommandArgument);
string fName = "teste" ;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fName);
Response.TransmitFile(Server.MapPath("~/uploadsadmin/" + fName));
Response.End();
}
}
Your method name in OnItemCommand = "Dwn" must match the method name in your code-behind. Rename your Save method to Dwn, or change your markup to match the Save method name.
Refactor the code like this:
if(e.CommandName == "Save")
{
int index = Convert.ToInt32(e.CommandArgument);
string fName = row.Cells[2].Text;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fName);
Response.TransmitFile(Server.MapPath("~/uploadsadmin/" + fName));
Response.End();
}
Put your breakpoint on the conditional (if...) and see if the breakpoint is hit.