How to open a file by clicking on HyperLink - c#

I have this table
I want to click on the link and the file (whatever file) will be opened in a new pop-up window.
Here is my code:
<asp:Repeater ID="dokumente" runat="server">
<ItemTemplate>
<tr>
<td><asp:HyperLink ID="HyperLink4" runat="server" Text='<%# Eval("DokuTyp") %>' NavigateUrl='file://<%# Eval("File") %>'></asp:HyperLink></td>
<td><%# Eval("Description")%></td>
<td><%# Eval("Date") %></td>
<td><%# Eval("File") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
But it doesn't work with NavigateUrl. Can anyone help me on this or any idea how to do this. Thanks

The file:/// is for resources on your own machine.
To open files on a server, you will have to link to urls on the server.
Use:
HttpContext.Current.Request.ResolveUrl(pathOnServer);
Change your code like this:
<asp:Repeater ID="dokumente" runat="server">
<ItemTemplate>
<tr>
<td><asp:HyperLink ID="HyperLink4" runat="server" Text='<%# Eval("DokuTyp") %>' NavigateUrl='<%# HttpContext.Current.Request.ResolveUrl(Eval("File")) %>'></asp:HyperLink></td>
<td><%# Eval("Description")%></td>
<td><%# Eval("Date") %></td>
<td><%# Eval("File") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
Where Server

The "file" protocol opens a file in the user computer.
I guess you have to read the file on the server-side and call a Resposne.Write.

If you want find file on server you can use Server.MapPath method; "file://" is not correct url if you want find file on server
NavigateUrl=<%#Server.MapPath(DataBinder.Eval("File"))%>

Related

How can I create a table with dynamic columns using asp.net controls?

Background: My data model is a List<PersonDetail>, where PersonDetail contains properties like FirstName, LastName, etc, and the List can be any size.
I want to create a table that can compare these PersonDetails side-by-side. This means for each column I need to take the data in a single PersonDetail and spread it across my 8 rows. Then do the same for the next PersonDetail.
I have a constraint where I can only use an Asp.Net control (ListView, GridView, Repeater, etc.) along with control.DataSource and control.DataBind() to create my table.
The template I want to do is something like:
<LayoutTemplate>
<table>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder2"></asp:PlaceHolder>
</tr>
<!-- and so on -->
</table>
</LayoutTemplate>
<ItemTemplate1>
<td>
<asp:Label ID="LabelFirstName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "FirstName")%>'></asp:Label>
</td>
</ItemTemplate1>
<ItemTemplate2>
<td>
<asp:Label ID="LabelLastName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "LastName")%>'></asp:Label>
</td>
</ItemTemplate2>
<!-- and so on -->
Where the above ItemTemplates would be the only parts that repeat in the table.
I've tried all three control options and it doesn't seem to be supported without complicating the code-behind.
Is there a better data model I could use that can interface with another control? I've seen solutions like DataTable, but not sure if that will solve my problem..
Any ideas?
<table border="1">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "FirstName") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "LastName") %></td>
</tr>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "Street") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "City") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>

Intermittent issue with Telerik TabStrip controls 'error creating control'

I've been getting an intermittent issue when i'm adding or using the telerik controls for tabstrip.
Here's what it looks like:
http://imgur.com/DYhXzNy
error creating control - telerik:RadTabStrip Duplicate component name 'RadTabStrip1'. Component names must be unique and case-insensitive.
What i've done:
Restarted VS
Uninstalled and reinstalled AJAX controls
Copied the Telerik.Web.UI bin file to my project's bin directory
All assemblies in web.config matches the current version of BIN i'm working on.
However, i'm still getting this issue more frequent than usual. It works again after clicking on the smart tag a couple of times or after restarting VS. recently, i had to keep on updating the BIN files and restart VS again to make it work. Also tried to clear VS cache but it keeps on happening. You guys have other suggestion on how i can permanently resolve this issue?
Update:
It happened again and seems to happen when try to follow the hierarchy w templates demo and do the following
Created a grid and included a nestedviewtemplate tag
made a radtabstrip inside the tag
placed one tab and added a multi page (used the smart tags at this point)
added a radlistview control. even added the placeholder tag.
Here's what i made after the tag
<telerik:RadMultiPage ID="RadMultiPage1" runat="server">
<telerik:RadPageView ID="RadPageView1" runat="server">
<telerik:RadListView ID="RadListView1" runat="server" ItemPlaceholderID="PlaceHolder1" DataKeyNames="JobOrderIndex" DataSourceID="SqlDataSource20">
<LayoutTemplate>
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</LayoutTemplate>
<ItemTemplate>
<table>
<tr>
<td><i>Job Order No.</i>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("JobOrderNumber", "{0}") %>'></asp:Label>
</td>
<th>Status</th>
<th>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("JobOrderStatus", "{0}") %>'></asp:Label>
</th>
</tr>
<tr>
<td>Plate Number</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("ProfitCenter", "{0}") %>'></asp:Label>
</td>
<td>Job Type</td>
<td>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("JobType", "{0}") %>'></asp:Label>
</td>
</tr>
<tr>
<td>Job Order Date</td>
<td>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("JobOrderDate", "{0:d}") %>'></asp:Label>
</td>
<td>Created By</td>
<td>
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td>Problem Description</td>
<td colspan="3">
<asp:Label ID="Label7" runat="server" Text='<%# Eval("ProblemDescription", "{0}") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadListView>
So, i noticed that the error occurs as soon as i place the source for the RadListView control and certain other controls or smart tags for the grid or the tab will not show up.
If you notice that i'm not doing anything right (which is most of the time) please let me know and i would appreciate the wisdom you can share with me so it can be the Telerik master race i ought to be.
Thanks again,
C
I figured it out, I eventually added a control .aspx page and this error occurs when 2 controls with the same ID is found in one module.

LinkButton in Repeater causes postback and button doesn't

Ok so I have an update panel sorrounding my controls. I have 2 dropdownlists which have functions they run from codebehind and a repeater of items. I've done the test in a Repeater using a button it doesn't do a postback, but the linkbutton does. What am I doing wrong?
also this is inside a usercontrol no aspx page.
<asp:UpdatePanel ID="upLocation" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:Repeater ID="rptMuniProducts" runat="server">
<HeaderTemplate>
<table class="table">
<thead>
<tr>
<th class="w80"></th>
<th>Product</th>
<th>Product Type</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="actions">
<asp:Button ID="btnProd" runat="server" OnClick="btnProd_Click" Text="test" />
<asp:LinkButton ID="lnkDeleteProd" runat="server" OnClick="lnkDeleteProd_Click">Link Test</asp:LinkButton>
<asp:HiddenField ID="hdnId" runat="server" Value='<%# DataBinder.Eval(Container, "DataItem.Id") %>' />
</td>
<td><%# DataBinder.Eval(Container, "DataItem.Name") %></td>
<td><%# DataBinder.Eval(Container, "DataItem.Producttype") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
Have you tried setting ClientIDMode=Auto on the LinkButton? There's a long-standing .NET bug with doPostBack and non-auto client ids.

Building Hyperlink Dynamically but need to perform another action also

I am populating a repeater on my asp.net web page (pop up) from a stored procedure call. I have a column where I need to build the hyperlink based on the values dynamically that calls an inquiry back to my original web form. However, the trouble I am having is that when I click on the link, I need to also retrieve some other data and insert this data into the viewstate.
The "GetListOfValues" function that I am calling obviously doesn't work the way I have this coded. Is there a way to accomplish this, and maybe even do it better than I am attempting to do it?
Here's my example:
Default.aspx
<asp:Repeater ID="rptReport" runat="server">
<HeaderTemplate>
<table>
<tr>
<td>Name</td>
<td>ID</td>
<td>Value1</td>
<td>Value2</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"Name") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"ID") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"Value1") %></td>
<td><%# GetValueTwoLink(Eval("Name"),Eval("Value2") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<%--This area holds totals for columns--%>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
Default.aspx.cs
protected string GetValueTwoLink(object name, object value2)
{
ViewState["ListOfValues"] = datalayer.GetListOfValues(name, value2);
return string.Format(
"{1}",
name,
Convert.ToInt32(value2).ToString("d"));
}
Any help would be appreciated!
Not exactly sure what you are trying to do with that onclick... but you can do it on the code-front:
<ItemTemplate>
<tr>
<td><%# Eval("Name") %></td>
<td><%# Eval("ID") %></td>
<td><%# Eval("Value1") %></td>
<td>
<a href="#"
onclick="<%# String.Format("window.opener.ViewValues('{0}')", DataBinder.Eval(Container.DataItem,"Name")) %>">
<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem, "Value2")).ToString("d")%>
</a>
</td>
</tr>
</ItemTemplate>
Also, as you see, you can just use
<%# Eval("Name") %>
instead of
<%# DataBinder.Eval(Container.DataItem,"Name") %>
to just show data. You use the DataBinder.Eval when you need to do some manipulation, like in the 4th <td>.

What is the easiest way to put an index to a repeater control in .NET?

I want an ASP:NET WebForms Repeater control to put an index next to each of its output rows automatically. How can I do that?
Example:
Name
1 John
2 Jack
3 Joe
Try the following:
<asp:Repeater ID="myRepeater" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Container.ItemIndex %></td>
<!-- or maybe -->
<td><%# Container.ItemIndex + 1 %></td>
<td><%# DataBinder.Eval(Container, "DataItem.Name") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

Categories