Hi say of have a table of cars in my SQL database. That table has a column for the car make and a column called picture of type:
Picture(image, null)
I'm then displaying my cars in a repeater and so it might look like this:
<asp:Repeater id="carsRepeater" runat="server" DataSourceID="CarsDataSource>
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label id="carMakeLabel" runat="Server" Text='<%# Eval("Make") %>' />
</td>
<td>
Some how display a clickable image here
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</Footer>
</asp:Repeater>
What I'm wanting is in column two to get the picture of the car to display and make it so you can click on that picture and it will run a method in the code behind. Also I have this requirement where the picture click method mustn't require javascript to run.
Can someone please give me an idea of how I would go about this?
I'm currently thinking about putting the image somehow in a link but I'm not sure how to display the image. Maybe the asp:Image but that requires an ImageUrl.
Try image button, it displays an image, doesn't require javascript and you can run a method on click event from code behind
Write an HTTPHandler (say CarImage.ashx) and in that handler, given ID of the image return the binary data with ContentType of image/gif (or whatever). Render an image tag in the datagrid with src as CarImage.ashx?ImageID=xxxxx. The process is described many place including this one.
Related
I have 2 page.
When double click row data in first page will be go to second page.
second page is for update purpose.
when successful update in second page and i want back to first page, the data show not updated in first page but when refresh the data will show updated record.
How can i get the updated record show in first page without click refresh?
below is first page aspx code:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr style="cursor: hand;" onmouseover="this.style.backgroundColor='#E6F0FF'"
onmouseout="this.style.backgroundColor='#FFFFFF'"
onclick="javascript:window.location.href='V_Updated.aspx?mail=<%#Eval("mail") %>'">
<td class="line_table_td" style="text-align: center;"><%#Eval(" mail ")%> </td>
<td class="line_table_td" style="text-align: center;"><%#Eval(" remarks ")%> </td>
</tr>
</ItemTemplate>
</asp:Repeater>
second page aspx button back code:
<td class="btn_bg" onclick = "history.back();">Back</td>
Better to use AJAX for updating data, if it is suitable for your project. This way you do not have to use two different pages.
http://www.webblogsforyou.com/ajax-introduction-how-to-use-ajax-in-asp-net-with-example/
Thanks!
Don't go back using the browser history (e.g. using history.back()). Different browsers handle caching differently, so it's difficult to control if your page would get refreshed. Provide a proper link to the previous page instead.
Simply put a link in second page like below :
<a href="firstpage.aspx" > Back </a>
I'm trying to create in a repeater a DropDownList and a TextBox for simulating a typical question list
My question is, how can I create 5 rows in my repeater with this dropdownlists and textboxes
Q: DropDownList1
A: TextBox1
Q: DropDownList2
A: TextBox2
Q: DropDownList3
A: TextBox3
Q: DropDownList4
A: TextBox4
Q: DropDownList5
A: TextBox5
Another day we could change the number of questions to 3, so my repeater should bind 3 Q-A
How can I do this dynamically.
I create the structure like this... but I don't know how to begin the Load event in order to render as I said before.
<asp:Repeater ID="repeater1" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:DropDownList ID="ddlQuestion" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtAnswer" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Easiest way might be to encapsulate those low-order controls in a higher order control (namely an ASCX) and then add that to the placeholder in a loop. This way you get the benefit of being able to easily change the ASCX without repercussions on the outer looping code.
Edit: "adding" means creating the controls and then attaching them as children.
I am working on a web application. The process regarding the problem is that I am fetching users comments from DB using Entity Framework Model. I am using a listview to show Customers Name, Rating and Comments.
The problem is that I am using a Ajax toolkit control called HTMLEditor for storing comments in the DB, so when I have to display the comments, I need the same control ie HTML Editor. Now when I use the following code to create the ITEMTEMPLATE for the listview,
<ItemTemplate>
<tr style="background-color:#EDECB3;color: #000000;">
<td><%# Eval("CustomerName")%></td>
<td> <img src='Styles/Images/ReviewRating<%# Eval("Rating") %>.png' alt="">
<br />
</td>
<td> <cc1:Editor ID="Comments" runat="server" Text="<%#Eval("Comments") %>"/>
</td>
</tr>
</ItemTemplate>
Everything is working except the line
<td> <cc1:Editor ID="Comments" runat="server" Text="<%#Eval("Comments") %>"/>
</td>
It says that the server tag is not well formed. please help.
Updated Error: I added nounicode="true". and the error I encountered is
Could not find any resources appropriate for the specified culture or
the neutral culture. Make sure
"AjaxControlToolkit.Properties.Resources.NET4.resources" was correctly
embedded or linked into assembly "AjaxControlToolkit" at compile time,
or that all the satellite assemblies required are loadable and fully
signed.
you should try
<cc1:Editor ID="Comments" runat="server" Text="<%#Eval('Comments') %>"/>
the text proprty is not the same.
Try below code:
Text='<%#Eval("Comments") %>'
Using the ScriptManager on the page solve the problem.
As far as the problem of displaying HTML text in HTML Editor is concerned, I decided not to use the HTML Editor from Ajax Control Toolkit. Rather I displayed the html text raw on the page using the html decoding utility like this,
<%#Server.HtmlDecode(Eval("Comments").ToString()) %>
"rr_only4you" told that answer is correct, i got the error like use blow one
Text="<%#Eval("Comments") %>"
after that i change that to
Text='<%# Eval("Comments") %>'
this format it will correct,
you use this one
<cc1:Editor ID="Comments" runat="server"><%# Eval("Comments") %></cc1>
I write a ASP.NET Application for creating a signatur and other stuff. And I use the AjaxToolkit with the CalenderExtender. I want if I click on a ImageButton that open the extender and the TextBox get the Data. It works fine but I don't see the ButtonImage :( >.<
Where I can get a Image for my ImageButton and how it works? Here my ASPX Site Code
...
<tr>
<td>Abwesenheit von: </td><td>
<asp:TextBox ID="txtAbwesenheitVon" runat="server" Enabled="false"></asp:TextBox>
<asp:ImageButton ID="imgbtnAbwesenheitVon" runat="server" ToolTip="Abwesenheit von..." PostBackUrl="~/App_Theme/Calender.ico" />
<asp:CalendarExtender ID="AbwesenheitVon" runat="server" TargetControlID="txtAbwesenheitVon"
Format="dd.MM.yyyy" PopupButtonID="imgbtnAbwesenheitVon"></asp:CalendarExtender>
</td>
</tr>
...
My second Question is.
Can I use a Label for the textBox, too?
But I see only this..._->
Replace
PostBackUrl="~/App_Theme/Calender.ico"
with
ImageUrl = "~/App_Theme/Calender.ico"
Image.ImageUrl Property
Use ImageUrl property instead of PostBackUrl
I have the following table in an ascx user controll:
<tr runat="server" id="rowChangeSerNo">
<td colspan="2">
<table id="tblChangeSerNo" runat="server">
</table>
</td>
</tr>
<tr id="row" runat="server">
<td>
<asp:Button ID="btChangeSerNo" runat="server" Text="Update" OnClick="btChangeSerNo_onClick" />
</td>
</tr>
I create the tblChangeSerNo dynamically with text boxes prefilled with the current values in the db. The idea of the control is to allow the user to update the values of the DB with new values. The problem is that when the btChangeSerNo_onClick method is called:
The table is not rendered, since I do it on pre-render
Even if I rendered the table on Page_Load I could not access updated values of the user because they are lost.
How can I solve this problem?
The best practice way will be to use Grid control instead.
If you prefer to stick with your own code, follow those steps:
Store all the text boxes in global fields, e.g. public List<TextBox> m_tableTextboxes = new List<TextBox>(); and when creating add to that list.
Have the code creating the dynamic controls in the Page_Load but execute it only when not is PostBack: if (!Page.IsPostBack) { ... }
In the button click event, read the values from your global field.
Done something similar in the past, so the concept should work.