List Info

Thread: RE: New to datagrids question




RE: New to datagrids question
country flaguser name
United States
2007-09-04 11:50:53

Normally I would set <%# DataBinder.Eval(Container, "DataItem.Name&quot;) %>
while filling a dataset with adapter or with a reader and assigning values
to <%# DataBinder.Eval(Container, "DataItem.Name&quot;) %> as each row is read
and rendered. The data grid is confusing me . I never used one before until
now.

so somewhere in here:

articleList.DataSource = dirInfo.GetFiles(&quot;*.*";)

'Before I bind somehow I need to make the url = the domain that I am working
with. So that is where I am confused. I also was trying to figure out how I
could just use a datareader and output the files that way with a
stringbuilder and making custom html list. I know it is probably easy to use
a datagrid but coming from asp classic it feels like osme things are just
more difficult in .net. I mean in asp classic making a list of files and
modifying alink on output was easy. I search google but find the same info
everywhere and it is usually working with a database and not file directory
contents.....

articleList.DataBind()

I have this in the code behind:

If Not IsPostBack Then

'PanelUser.Visible = False

'PanelAdmin.Visible = False

'PanelNoAccess.Visible = True

Dim strFtpFolder

strFtpFolder = Session(&quot;FtpFolder")

Dim dirInfo As New DirectoryInfo(strFtpFolder)

'Dim dirInfo As New DirectoryInfo(Server.MapPath(&quot;"))

'articleList.DataSource = dirInfo.GetFiles(&quot;*.aspx&quot;)

articleList.DataSource = dirInfo.GetFiles(&quot;*.*";)

articleList.DataBind()

End If 'If Not IsPostBack Then

IN ASPX PAGE SOURCE:
'''''''''''''''

<FORM id="Form1" runat=&quot;server&quot;>

<asp:label id="lblMessage&quot; runat=&quot;server&quot; ForeColor="Red&quot;
Font-Italic=&quot;True&quot;></asp:label>

&lt;aspataGrid id="articleList&quot; runat=&quot;server&quot; Font-Size="Smaller"
OnDeleteCommand=";articleList_DeleteFile"

OnItemDataBound=&quot;articleList_ItemDataBound&quot; DataKeyField="FullName&quot;
HeaderStyle-Font-Bold=&quot;True";

HeaderStyle-Font-Size=&quot;15pt&quot; HeaderStyle-ForeColor="White"
HeaderStyle-BackColor="Navy" AlternatingItemStyle-BackColor="#eeeeee"

AutoGenerateColumns="False" Font-Name="Verdana" Font-Names="Verdana"
Width=&quot;615px&quot;>

<FooterStyle Font-Size="Smaller"&gt;</FooterStyle>

<AlternatingItemStyle BackColor="#EEEEEE"&gt;</AlternatingItemStyle>

<HeaderStyle Font-Size="Larger" Font-Bold="True&quot; ForeColor="White"
BackColor=&quot;Navy&quot;></HeaderStyle>

<Columns>

&lt;asp:ButtonColumn Text=";Delete&quot; ButtonType="PushButton&quot;
CommandName=&quot;Delete&quot;><;/asp:ButtonColumn>;

<asp:TemplateColumn HeaderText="File Name">

&lt;ItemTemplate>

<asp:HyperLink runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container,
&quot;DataItem.Name";) %>' NavigateUrl='<%# DataBinder.Eval(Container,
&quot;DataItem.Name";) %>'>

</asp:HyperLink>

</ItemTemplate>

</asp:TemplateColumn>;

<asp:BoundColumn DataField="LastWriteTime&quot; HeaderText="Last Write Time"
DataFormatString=&quot;{0:d}&quot;>

<ItemStyle HorizontalAlign=&quot;Center&quot;><;/ItemStyle>

&lt;/asp:BoundColumn>;

<asp:BoundColumn DataField="Length" HeaderText="File Size"
DataFormatString=&quot;{0:#,### bytes}&quot;>

<ItemStyle HorizontalAlign=&quot;Right&quot;></ItemStyle&gt;

&lt;/asp:BoundColumn>

</Columns>

</aspataGrid>;</FORM>

_____

From: AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com
[mailto: AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com] On Behalf Of Dean Fiala
Sent: Thursday, August 30, 2007 10:30 PM
To: AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com
Subject: Re: [AspNetAnyQuestionIsOk] New to datagrids question

If you just put the file name in as the DataNavigateUrlField it will assume
a relative address to your application. If you want to create an absolute
link you need to specify the full URL.

The easiest way to do this is make the column a template column, and set the
NavigateURL in the Item_DataBound event of the grid. Something like this...

if e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem then
Dim FileRow as DataViewRow = e.Item.DataRow
Dim FileLink as HyperLink = e.Item,FindControl(&quot;HyperLinkName&quot;)
Dim FileName as String = FileRow(&quot;Name&quot;)

FileLink.NavigateURL = String.Format("http://{0}/", DomainVariable,
FileName)
End if

On 8/30/07, mbelcher <AspNetAnyQuestionIs
<mailto:AspNetAnyQuestionIsOk%40faroutcomputersystems.com>
Ok%40faroutcomputersystems.com">Okfaroutcomputersystems.com>
wrote:
>
> I have a page that lists the contents of a folder. It all works fine. The
> thing is that this will also need to allow for the files to be downloaded.
> My problem is that I can list up any folder on the server but of course
&gt; the
> hyperlink in the
>
> "&quot;"&quot;"&quot;<asp:HyperLinkColumn DataNavigateUrlField="Name"
&gt; DataTextField="Name"
> HeaderText="File Name"></asp:HyperLinkColumn>"&quot;"&quot;"
>
>; section will have a URL pointing to the current application. If the
> website
> where the code is running is www.datagrids.com <http://www.datagrid
<http://www.datagrids.com/> s.com/>
> then the URL's for the files will be www.datagrids.com/FILENAME no matter
&gt; what site the folder contents are actually in. I have a Domain Variable
> that
>; I would like to replace this with. I am getting lsot finding a way to do
> this within this asp:HyperLinkColumn tag... For instance if the file name
>; is Worktimes.doc ..... How can I make the beginning of the URL the value I
> have in the domain variable instead of the default which basically is
> where
&gt; the app is running?
>
>;
> So instead of the default www.datagrids.com <http://www.datagrid
<http://www.datagrids.com/> s.com/> /
> Worktimes.doc it will be MyDomianNamevariable/ Worktimes.doc
>
>
&gt; Mike
>;
>
>
> [Non-text portions of this message have been removed]
>
>;
>
>
> Yahoo! Groups Links
&gt;
>
>
>;

--
Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw. <http://www.vpsw.com/blogbaby&gt; com/blogbaby
Microsoft MVP

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity
Visit Your Group
New web site?

Drive traffic now.

Get your business

on Yahoo! search.

Yoga Resources

on Yahoo! Groups

Take the stress

out of your life.

Re: New to datagrids question
country flaguser name
United States
2007-09-05 07:45:42

One reason I avoid the scripting syntax is that this hard to do anything
fun.

So, instead, I use the Item_DataBound event as I showed you in my previous
post. It gets called every time a row is bound to the grid. This is where
you can make your changes to the URL of every item. You are already calling
the event.

Just change this...

<asp:HyperLink runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container,
&quot;DataItem.Name";) %>' NavigateUrl='<%# DataBinder.Eval(Container,
&quot;DataItem.Name";) %>'>

</asp:HyperLink>

into...
<asp:HyperLink runat=&quot;server&quot; id="FileHyperLink" />

and change your code in the ItemData_Bound event into something like this...

if e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem then
Dim FileRow as DataViewRow = e.Item.DataRow
Dim FileLink as HyperLink = e.Item,FindControl(&quot;FileHyperLink&quot;)
Dim FileName as String = FileRow(&quot;Name&quot;)

FileLink.NavigateURL = String.Format("http://{0}/", DomainVariable,
FileName)
FileLink.Text = FileRow(&quot;Name&quot;)
End if

On 9/4/07, mbelcher < AspNetAnyQuestionIsOk%40faroutcomputersystems.com">AspNetAnyQuestionIsOkfaroutcomputersystems.com> wrote:
&gt;
> Normally I would set <%# DataBinder.Eval(Container, "DataItem.Name&quot;) %>
&gt; while filling a dataset with adapter or with a reader and assigning values
&gt; to <%# DataBinder.Eval(Container, "DataItem.Name&quot;) %> as each row is read
>; and rendered. The data grid is confusing me . I never used one before
&gt; until
&gt; now.
>;
> so somewhere in here:
&gt;
> articleList.DataSource = dirInfo.GetFiles(&quot;*.*";)
>
>
>; 'Before I bind somehow I need to make the url = the domain that I am
> working
> with. So that is where I am confused. I also was trying to figure out how
> I
> could just use a datareader and output the files that way with a
> stringbuilder and making custom html list. I know it is probably easy to
> use
> a datagrid but coming from asp classic it feels like osme things are just
>; more difficult in .net. I mean in asp classic making a list of files and
> modifying alink on output was easy. I search google but find the same info
>; everywhere and it is usually working with a database and not file
>; directory
> contents.....
>
>
&gt;
>
>
&gt; articleList.DataBind()
>
>
&gt;
>
>
>;
> I have this in the code behind:
>
>
> If Not IsPostBack Then
>;
>
>
> 'PanelUser.Visible = False
&gt;
> 'PanelAdmin.Visible = False
&gt;
> 'PanelNoAccess.Visible = True
>;
> Dim strFtpFolder
>
> strFtpFolder = Session(&quot;FtpFolder")
>
&gt;
>
> Dim dirInfo As New DirectoryInfo(strFtpFolder)
&gt;
> 'Dim dirInfo As New DirectoryInfo(Server.MapPath(&quot;"))
>
>
>;
> 'articleList.DataSource = dirInfo.GetFiles(&quot;*.aspx&quot;)
>;
> articleList.DataSource = dirInfo.GetFiles(&quot;*.*";)
>
>
>;
> articleList.DataBind()
>
>
&gt;
>
>
>;
>
> End If 'If Not IsPostBack Then
>;
>
>
>
> IN ASPX PAGE SOURCE:
> '''''''''''''''
&gt;
>
> <FORM id="Form1" runat=&quot;server&quot;>
>
>
> <asp:label id="lblMessage&quot; runat=&quot;server&quot; ForeColor="Red&quot;
> Font-Italic="True">;</asp:label>
>
>;
> <aspataGrid id="articleList&quot; runat=&quot;server&quot; Font-Size="Smaller"
> OnDeleteCommand=&quot;articleList_DeleteFile"
>
>;
> OnItemDataBound=&quot;articleList_ItemDataBound"; DataKeyField="FullName&quot;
> HeaderStyle-Font-Bold="True"
>
>
> HeaderStyle-Font-Size="15pt" HeaderStyle-ForeColor="White"
> HeaderStyle-BackColor="Navy" AlternatingItemStyle-BackColor="#eeeeee"
>
>;
> AutoGenerateColumns="False" Font-Name="Verdana" Font-Names="Verdana"
> Width=&quot;615px&quot;>
&gt;
>
> <FooterStyle Font-Size="Smaller"&gt;</FooterStyle>
>
&gt;
> <AlternatingItemStyle BackColor="#EEEEEE"&gt;</AlternatingItemStyle>
>
&gt;
> <HeaderStyle Font-Size="Larger" Font-Bold="True&quot; ForeColor="White"
&gt; BackColor="Navy&quot;>&lt;/HeaderStyle>
>
>
> <Columns>
>;
>
> <asp:ButtonColumn Text=";Delete&quot; ButtonType="PushButton&quot;
> CommandName="Delete"&gt;</asp:ButtonColumn>
>
>
> <asp:TemplateColumn HeaderText="File Name">
>
>
&gt; <ItemTemplate>
>
&gt;
> <asp:HyperLink runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container,
&gt; "DataItem.Name&quot;) %>' NavigateUrl='<%# DataBinder.Eval(Container,
&gt; "DataItem.Name&quot;) %>'>
>
&gt;
> </asp:HyperLink>;
>
>
> </ItemTemplate>
>
&gt;
> </asp:TemplateColumn>
&gt;
>
> <asp:BoundColumn DataField="LastWriteTime&quot; HeaderText="Last Write Time"
> DataFormatString=&quot;{0:d}&quot;>
&gt;
>
> <ItemStyle HorizontalAlign=&quot;Center&quot;><;/ItemStyle>
>
>
&gt; </asp:BoundColumn&gt;
>
>
&gt; <asp:BoundColumn DataField="Length" HeaderText="File Size"
> DataFormatString=&quot;{0:#,### bytes}&quot;>
&gt;
>
> <ItemStyle HorizontalAlign=&quot;Right&quot;></ItemStyle&gt;
>
>
&gt; </asp:BoundColumn&gt;
>
>
&gt; </Columns>
&gt;
>
> </aspataGrid>;</FORM>
>
>
&gt;
> _____
&gt;
> From: AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com
&gt; [mailto: AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com] On Behalf Of Dean Fiala
&gt; Sent: Thursday, August 30, 2007 10:30 PM
> To: AspNetAnyQuestionIsOk%40yahoogroups.com">AspNetAnyQuestionIsOkyahoogroups.com
&gt; Subject: Re: [AspNetAnyQuestionIsOk] New to datagrids question
>
>;
>
> If you just put the file name in as the DataNavigateUrlField it will
>; assume
&gt; a relative address to your application. If you want to create an absolute
> link you need to specify the full URL.
>;
> The easiest way to do this is make the column a template column, and set
> the
> NavigateURL in the Item_DataBound event of the grid. Something like
>; this...
>
> if e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
> ListItemType.AlternatingItem then
>; Dim FileRow as DataViewRow = e.Item.DataRow
> Dim FileLink as HyperLink = e.Item,FindControl(&quot;HyperLinkName&quot;)
> Dim FileName as String = FileRow(&quot;Name&quot;)
>;
> FileLink.NavigateURL = String.Format("http://{0}/", DomainVariable,
>; FileName)
> End if
>
> On 8/30/07, mbelcher <AspNetAnyQuestionIs
> <mailto:AspNetAnyQuestionIsOk%40faroutcomputersystems.com&gt;
> Ok%40faroutcomputersystems.com">Okfaroutcomputersystems.com>
> wrote:
&gt; >
>; > I have a page that lists the contents of a folder. It all works fine.
&gt; The
> > thing is that this will also need to allow for the files to be
> downloaded.
> > My problem is that I can list up any folder on the server but of course
&gt; > the
> > hyperlink in the
> >
>; > "&quot;"&quot;"&quot;<asp:HyperLinkColumn DataNavigateUrlField="Name"
&gt; > DataTextField="Name"
> > HeaderText="File Name"></asp:HyperLinkColumn>"&quot;"&quot;"
> >
>; > section will have a URL pointing to the current application. If the
> > website
> > where the code is running is www.datagrids.com <http://www.datagrid
> <http://www.datagrids.com/> s.com/>
> > then the URL's for the files will be www.datagrids.com/FILENAME no
> matter
&gt; > what site the folder contents are actually in. I have a Domain Variable
> > that
>; > I would like to replace this with. I am getting lsot finding a way to do
> > this within this asp:HyperLinkColumn tag... For instance if the file
>; name
>; > is Worktimes.doc ..... How can I make the beginning of the URL the value
&gt; I
> > have in the domain variable instead of the default which basically is
> > where
&gt; > the app is running?
> >
>; >
>; > So instead of the default www.datagrids.com <http://www.datagrid
> <http://www.datagrids.com/> s.com/> /
> > Worktimes.doc it will be MyDomianNamevariable/ Worktimes.doc
> >
>; >
>; > Mike
>; >
>; >
>; >
>; > [Non-text portions of this message have been removed]
> >
>; >
>; >
>; >
>; > Yahoo! Groups Links
&gt; >
>; >
>; >
>; >
>;
> --
> Dean Fiala
&gt; Very Practical Software, Inc
> Now with Blogging...
> http://www.vpsw. <http://www.vpsw.com/blogbaby&gt; com/blogbaby
> Microsoft MVP
>
> [Non-text portions of this message have been removed]
>
>;
>
>
>
> [Non-text portions of this message have been removed]
>
>;
>
>
> Yahoo! Groups Links
&gt;
>
>
>;

--
Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity
Visit Your Group
Y! Messenger

Quick file sharing

Send up to 1GB of

files in an IM.

Best of Y! Groups

Check out the best

of what Yahoo!

Groups has to offer.

Yoga Groups

Find Enlightenment

&amp; exchange insights

with other members

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )