Ø
Øyvind Isaksen
I have a datagrid that displays all files in a folder. It works good, but I
need a extra column with a link for choosing image.
As shown in the code below I have made an ItemTemplate for this, and what I
need to do is to put the filename in the CommandArgument. How do I do that??
Is this the right way to do it, or is it a smarter way to put the filename
in a session-variable when clicking on the "Use this image"-LinkButton ?
-------------------------------------------------
DataGrid:
-------------------------------------------------
<asp:datagrid id="dtgFilelist" runat="server" autogeneratecolumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="lnkChooseImage" Runat="server"
CommandName="chooseImage" CommandArgument="[HERE I WANT THE FILENAME]">Use
this image</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:HyperLinkColumn DataNavigateUrlField="Name"
DataTextField="Name" HeaderText="Filename" />
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Date"
DataFormatString="{0:d}" />
<asp:BoundColumn DataField="Length" HeaderText="Size"
DataFormatString="{0:#,### bytes}" />
</Columns>
</asp:datagrid>
-------------------------------------------------
Code Behind:
-------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dirInfo As New DirectoryInfo(Server.MapPath("/uploads/"))
Me.dtgFilelist.DataSource = dirInfo.GetFiles("*.*")
Me.dtgFilelist.DataBind()
End Sub
Private Sub dtgFilelist_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dtgFilelist.ItemCommand
Dim KommandoNavn As String = e.CommandName
If e.CommandName = "chooseImage" Then
session("image") = e.CommandArgument
'I also tried this:
'session("image") = e.Item.Cells(0).Text
End If
End Sub
Thanks for helping me!!!
need a extra column with a link for choosing image.
As shown in the code below I have made an ItemTemplate for this, and what I
need to do is to put the filename in the CommandArgument. How do I do that??
Is this the right way to do it, or is it a smarter way to put the filename
in a session-variable when clicking on the "Use this image"-LinkButton ?
-------------------------------------------------
DataGrid:
-------------------------------------------------
<asp:datagrid id="dtgFilelist" runat="server" autogeneratecolumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="lnkChooseImage" Runat="server"
CommandName="chooseImage" CommandArgument="[HERE I WANT THE FILENAME]">Use
this image</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:HyperLinkColumn DataNavigateUrlField="Name"
DataTextField="Name" HeaderText="Filename" />
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Date"
DataFormatString="{0:d}" />
<asp:BoundColumn DataField="Length" HeaderText="Size"
DataFormatString="{0:#,### bytes}" />
</Columns>
</asp:datagrid>
-------------------------------------------------
Code Behind:
-------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dirInfo As New DirectoryInfo(Server.MapPath("/uploads/"))
Me.dtgFilelist.DataSource = dirInfo.GetFiles("*.*")
Me.dtgFilelist.DataBind()
End Sub
Private Sub dtgFilelist_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dtgFilelist.ItemCommand
Dim KommandoNavn As String = e.CommandName
If e.CommandName = "chooseImage" Then
session("image") = e.CommandArgument
'I also tried this:
'session("image") = e.Item.Cells(0).Text
End If
End Sub
Thanks for helping me!!!