cronan gogarty wrote:
> I think my problem is a little more basic than this!
>
> I have been looking at examples all weekend and I
> still havent found a solution.

Well, your best bet is to avoid the BoundColumn and just use a TemplateColumn instead.

> So in essence what I want is
> 1 datagrid with;
> 1 a col containg checkboxes
> 2 a boundcol containing the filename
> 3 a col displaying an image dependent on the
>   file extension
> 4 a col displaying a hyperlink to perform some
>   actions on the file

<asp:DataGrid ID="myGrid" OnItemCommand="myGrid_OnItemCommand" OnItemDataBound="myGrid_OnItemDataBound" Runat="server">
<Columns>
<asp:TemplateColumn>
<asp:CheckBox ID="myCbx" Runat="server"/>
</asp:TemplateColumn>
<asp:TemplateColumn>
<%# (string) Container.DataItem %>
</asp:TemplateColumn>
<asp:TemplateColumn>
<asp:Image ID="myImg" ImageUrl='<%# "/images" + ((string) Container.DataItem %>' Runat="server"/>
</asp:TemplateColumn>
<asp:TemplateColumn>
<asp:LinkButton ID="myLink" Text="..." Runat="server"/>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>


So there are your columns. I assume that the image shouldn't show if the file in question isn't actually in image, so you will want to change its visibility as soon as it's bound (thus, the ItemDataBound event handler).

protected void myGrid_OnItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.Alternating Item)
{
// don't do anything if the current row is not an item or alternating item
return;
}
string file = (string) e.Item.DataItem;
if (!file.EndsWith(".jpg") || !file.EndsWith(".gif") || !file.EndsWith(".png"))
{
Image img = (Image) e.Item.FindControl("myImg");
img.Visible = false;
}
}


Lastly, an event handler for when the LinkButton is clicked.

protected void myGrid_OnItemCommand(object sender, DataGridCommandEventArgs e)
{
string file = (string) e.Item.DataItem;
Response.Redirect("Somefile.aspx?file=" + Server.HtmlEncode(file), true);
}


HTH.
--
::::::::::::::::::::::::::::::
Howard Cheng
http://www.howcheng.com/
Wise-cracking quote goes here.

____ • The WDVL Discussion List from WDVL.COM • ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] Send Your Posts To: [EMAIL PROTECTED]
To set a personal password send an email to [EMAIL PROTECTED] with the words: "set WDVLTALK pw=yourpassword" in the body of the email.
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub


________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.



Reply via email to