databind a grid with linkbutton

  • Thread starter Thread starter Nikhil Patel
  • Start date Start date
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.
 
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
 
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
 
Back
Top