repeater control

Posted by Falak under ASP.NET on 9/14/2009 | Views : 2562 | Status : [Member] | Replies : 6
this is code
but using this only one file open
i want each hyperlink open different file
plz help me
and i use vb.net LANGUAGE

<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<script runat="server">
sub Page_Load
Dim sqlconn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
sqlconn.Open()
Dim cmd As New SqlCommand("Select * From myfiles", sqlconn)
Dim dbread = cmd.ExecuteReader()
customers.DataSource = dbread
customers.DataBind()
dbread.Close()
sqlconn.Close()
end sub
</script>

<body>

<form id="Form1" runat="server">
<asp:Repeater id="customers" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="customers_ItemCommand">
<HeaderTemplate>
<table border="1" width="100%">
<tr bgcolor="#b0c4de">

<th>File ID</th>

<th>File Name</th>

<th>File Path</th>
</tr>

</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="#f0f0f0">
<td><%#Container.DataItem("FileID")%> </td>
<td><%#Container.DataItem("FileName")%> </td>
<td> <asp:HyperLink ID="HyperLink1" runat="server" Style="z-index: 100" NavigateUrl ="~/Ali.doc" Text="hyperlink">Open File</asp:HyperLink></td>
</tr>

</ItemTemplate>

<FooterTemplate>
</table>
</FooterTemplate>


</form>

</body>
</html>





Responses

Posted by: Vuyiswamb on: 9/14/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day

Now let us Concerntrate on the important part this part

<asp:HyperLink ID="HyperLink1" runat="server" Style="z-index: 100" NavigateUrl ="~/Ali.doc" Text="hyperlink">Open File</asp:HyperLink>


Do you want to bind the Hyper link Control to a URL ?

When you Bind the Repeater , do you is there a field that has a URL ?


From Above you have hardcoded the Navigational URL to a Document. tell me the Structure of this query

Select * From myfiles


and i will help.

Thank you for posting at Dotnetfunda

Vuyiswa Maseko




Thank you for posting at Dotnetfunda
[Administrator]

Falak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/15/2009 [Member] [MVP] Bronze

Up
0
Down
Vuyiswamb is correct, this part is the problem:


<td> <asp:HyperLink ID="HyperLink1" runat="server" Style="z-index: 100" NavigateUrl ="~/Ali.doc" Text="hyperlink">Open File</asp:HyperLink></td>

You are hard coding the ali.doc into the link rather than binding it.

You should use a HttpHandler to serve the files. If you set it up so that it takes an ID in the querystring then you can replace the example above with something like:

<td> <asp:HyperLink ID="HyperLink1" runat="server" Style="z-index: 100" NavigateUrl ='<%# String.Format("~/FileDownload.ashx?FileID={0}", Container.DataItem("FileID")) %>'
Text='<%# String.Format(" Download {0}", Container.DataItem("FileName")) %>' /></td>

This is a good httphandler file download introduction:

http://blogs.msdn.com/petel/archive/2005/12/01/499189.aspx


Falak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 9/15/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
My name is Vuyiswa :)

Thank you for posting at Dotnetfunda
[Administrator]

Falak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/15/2009 [Member] [MVP] Bronze

Up
0
Down
Haha, at first I had xx is correct and I meant to go back and check your name but forgot it.

Then I noticed I had posted that so quickly changed it! Sorry :)

Falak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 9/15/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Its ok I understand. we are going to make sure that you will be seeing all the Replies of the threads in Dotnetfunda.

Thanks

Thank you for posting at Dotnetfunda
[Administrator]

Falak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/15/2009 [Member] [MVP] Bronze

Up
0
Down
yes that would be a handy feature

Falak, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response