databind a grid with linkbutton

N

Nikhil Patel

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.
 
G

Guest

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
 
N

Nikhil Patel

Thanks Bill.

Bill Borg said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,186
Latest member
vinaykumar_nevatia

Latest Threads

Top