trying to show images in the grid

A

androoo

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"
CommandName="Delete"></asp:But­tonColumn>


would become :
<asp:TemplateColumn>
<ItemTemplate>
<asp:ImageButton id="cmdDel" runat="server"
CommandName="Delete"
ImageUrl="pics/DELETE.JPG"
CausesValidation="false"></asp­:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>


but i just get a message saying Specified cast is not valid.
any ideas on what i may be doing .. here is the complete listing of my
grid code when its working without the template column for the delete
button:


<asp:datagrid id="dgReportCode" runat="server"
OnItemDataBound="dgReportCode_­ItemDataBound" DataKeyField="ID"
OnDeleteCommand="dgReportCode_­Delete"
OnUpdateCommand="dgReportCode_­Update"
OnCancelCommand="dgReportCode_­Cancel"
OnEditCommand="dgReportCode_Ed­it"
HeaderStyle-Font-Bold="True" HeaderStyle-HorizontalAlign="C­enter"
HeaderStyle-ForeColor="Black" HeaderStyle-BackColor="Gold"
AutoGenerateColumns="False" CellPadding="2" ForeColor="Black">
<HeaderStyle Font-Size="8pt" Font-Names="Verdana" Font-Bold="True"
HorizontalAlign="Center"
ForeColor="Gold"BackColor="Nav­y"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:But­tonColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:ImageButton id="ImageButton1" CommandName="Edit"
runat="server"
ImageUrl="pics/NOTEBOOK.JPG"><­/asp:ImageButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton id="Button4" runat="server"
Text="Update"
CommandName="Update" CausesValidation="false"></asp­:LinkButton>
<asp:LinkButton id="Button3" runat="server"
Text="Cancel"
CommandName="Cancel" CausesValidation="false"></asp­:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ReportName" HeaderText="Report
Name"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Code">
<ItemTemplate>
<%# DataBinder.Eval(Container.Data­Item,
"Code") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=txtCode runat="server" Text='<%#
Container.DataItem("Code") %>' columns="70" TextMode="MultiLine"
Wrap="True" Rows="5"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Version"
HeaderText="Ver"></asp:BoundCo­lumn>
</Columns>
</asp:datagrid>
 
S

societopia.net

Your datagrid code works find on my server
http://www.societopia.net/samples/webform3.aspx

Check the code that you put in the dgReportCode_­ItemDataBound procedure.
You might have attempted to cast a variable to the wrong type.


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"
CommandName="Delete"></asp:But­tonColumn>


would become :
<asp:TemplateColumn>
<ItemTemplate>
<asp:ImageButton id="cmdDel" runat="server"
CommandName="Delete"
ImageUrl="pics/DELETE.JPG"
CausesValidation="false"></asp­:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>


but i just get a message saying Specified cast is not valid.
any ideas on what i may be doing .. here is the complete listing of my
grid code when its working without the template column for the delete
button:


<asp:datagrid id="dgReportCode" runat="server"
OnItemDataBound="dgReportCode_­ItemDataBound" DataKeyField="ID"
OnDeleteCommand="dgReportCode_­Delete"
OnUpdateCommand="dgReportCode_­Update"
OnCancelCommand="dgReportCode_­Cancel"
OnEditCommand="dgReportCode_Ed­it"
HeaderStyle-Font-Bold="True" HeaderStyle-HorizontalAlign="C­enter"
HeaderStyle-ForeColor="Black" HeaderStyle-BackColor="Gold"
AutoGenerateColumns="False" CellPadding="2" ForeColor="Black">
<HeaderStyle Font-Size="8pt" Font-Names="Verdana" Font-Bold="True"
HorizontalAlign="Center"
ForeColor="Gold"BackColor="Nav­y"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:But­tonColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:ImageButton id="ImageButton1" CommandName="Edit"
runat="server"
ImageUrl="pics/NOTEBOOK.JPG"><­/asp:ImageButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton id="Button4" runat="server"
Text="Update"
CommandName="Update" CausesValidation="false"></asp­:LinkButton>
<asp:LinkButton id="Button3" runat="server"
Text="Cancel"
CommandName="Cancel" CausesValidation="false"></asp­:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ReportName" HeaderText="Report
Name"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Code">
<ItemTemplate>
<%# DataBinder.Eval(Container.Data­Item,
"Code") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=txtCode runat="server" Text='<%#
Container.DataItem("Code") %>' columns="70" TextMode="MultiLine"
Wrap="True" Rows="5"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Version"
HeaderText="Ver"></asp:BoundCo­lumn>
</Columns>
</asp:datagrid>
 
A

androoo

Thanks i did, and i saw it straight away, thanks for pointing it out.
even the error message makes sense now !

tnakyou for taking the time to put it on your server and test
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top