473,382 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

databind a grid with linkbutton

Hi all,
I am binding a grid to an array of the System.IO.FileInfo class. I need
to display the Name column as Link Button and its target should be the Full
Name of the file. How can I do this?

Thanks.
Nov 18 '05 #1
2 1352
Nikhil, there are a few ways to do this, but I'd probably go (vb syntax):

Build the list of files and bind to datagrid...
Dim di As DirectoryInfo = New DirectoryInfo("c:\wherever")
Dim fi() As FileInfo = di.GetFiles
With DataGrid1
.DataSource = fi
.DataBind()
End With

Set up a template column for the datagrid that has the Name to display, and
sets the CommandArgument to the full name, something like...
<asp:TemplateColumn>
<ItemTemplate>
<asp:linkbutton id="lnkFileName" runat="server" text='<%
#container.dataitem.name %>' commandargument='<%#
container.dataitem.fullname %>'></asp:linkbutton>
</ItemTemplate>
</asp:TemplateColumn>

Then handle the ItemCommand event, get the CommandArgument, do
response.redirect, etc.

hth,

Bill

"Nikhil Patel" wrote:
Hi all,
I am binding a grid to an array of the System.IO.FileInfo class. I need
to display the Name column as Link Button and its target should be the Full
Name of the file. How can I do this?

Thanks.

Nov 18 '05 #2
Thanks Bill.

"Bill Borg" <Bi******@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
Nikhil, there are a few ways to do this, but I'd probably go (vb syntax):

Build the list of files and bind to datagrid...
Dim di As DirectoryInfo = New DirectoryInfo("c:\wherever")
Dim fi() As FileInfo = di.GetFiles
With DataGrid1
.DataSource = fi
.DataBind()
End With

Set up a template column for the datagrid that has the Name to display,
and
sets the CommandArgument to the full name, something like...
<asp:TemplateColumn>
<ItemTemplate>
<asp:linkbutton id="lnkFileName" runat="server" text='<%
#container.dataitem.name %>' commandargument='<%#
container.dataitem.fullname %>'></asp:linkbutton>
</ItemTemplate>
</asp:TemplateColumn>

Then handle the ItemCommand event, get the CommandArgument, do
response.redirect, etc.

hth,

Bill

"Nikhil Patel" wrote:
Hi all,
I am binding a grid to an array of the System.IO.FileInfo class. I
need
to display the Name column as Link Button and its target should be the
Full
Name of the file. How can I do this?

Thanks.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
7
by: androoo | last post by:
Hi I am learing how to use the grid in asp.net. Im trying to replace the button columns with nice friendly images. So : <asp:ButtonColumn Text="Delete"...
2
by: androoo | last post by:
Hi I am learing how to use the grid in asp.net. Im trying to replace the button columns with nice friendly images. So : <asp:ButtonColumn Text="Delete"...
1
by: Craig | last post by:
This is killing me, I've been trying to figure this out for 2 days. When I click on the linkbutton, it executes the GetData(int) method to set the DataSource. The FAILURE is when it tries to...
2
by: jslaybaugh | last post by:
I am trying to bind to a GridView or DetailsView after a callback using the ClientCallback Manager in the new .NET 2.0 framework. See below for the HTML followed by the VB code: <html...
0
by: Dave | last post by:
Hi, I have a very simple page where i am using Page.ParseControl to create a datagrid control. When i try to run the DataBind method i get various errors. The code for the datagrid is as...
12
by: brwalias | last post by:
Hi, using .net 2 sql server 2005 Here is my situation: I'm passing a variable in the url from a selection on Page A and need to display the results on the Results page be based on that...
2
by: poornimanithya76 | last post by:
Hi, i am tried to convert below piece of code from data grid to grid view. since grid view is not having item created event so i try to implement with row Created. i am unable to perform whole...
1
by: RN1 | last post by:
Consider the following code which binds records from a DB to a Repeater: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim dSet As DataSet Dim sqlConn As...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.