T
tshad
I have an ItemDataBound event for my delete button and am getting an error:
System.InvalidCastException: Specified cast is not valid.
The event code:
********************************************************
public void articleList_ItemDataBound(Object sender, DataGridItemEventArgs
e)
{
// First, make sure we're NOT dealing with a Header or Footer row
if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType !=
ListItemType.Footer))
{
// Now, reference the Button control that the Delete ButtonColumn
// has been rendered to
Button deleteButton = (Button)e.Item.Cells[0].Controls[0]; <-- the
error
******************************************************************
The DataGrid looks like:
<asp:datagrid id="articleList" runat="server" HeaderStyle-Font-Bold="True"
HeaderStyle-Font-Size="15pt"
HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Navy"
AlternatingItemStyle-BackColor="#eeeeee"
AutoGenerateColumns="False" Font-Name="Verdana" DataKeyField="FullName"
OnItemDataBound="articleList_ItemDataBound"
OnDeleteCommand="articleList_DeleteFile">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name" />
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time"
ItemStyle-HorizontalAlign="Center"
DataFormatString="{0:d}" />
<asp:BoundColumn DataField="Length" HeaderText="File Size"
ItemStyle-HorizontalAlign="Right" DataFormatString="{0:#,##0 bytes}" />
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
CommandName="Delete" />
</Columns>
</asp:datagrid>
What is wrong with the cast?
Thanks,
Tom
System.InvalidCastException: Specified cast is not valid.
The event code:
********************************************************
public void articleList_ItemDataBound(Object sender, DataGridItemEventArgs
e)
{
// First, make sure we're NOT dealing with a Header or Footer row
if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType !=
ListItemType.Footer))
{
// Now, reference the Button control that the Delete ButtonColumn
// has been rendered to
Button deleteButton = (Button)e.Item.Cells[0].Controls[0]; <-- the
error
******************************************************************
The DataGrid looks like:
<asp:datagrid id="articleList" runat="server" HeaderStyle-Font-Bold="True"
HeaderStyle-Font-Size="15pt"
HeaderStyle-ForeColor="White" HeaderStyle-BackColor="Navy"
AlternatingItemStyle-BackColor="#eeeeee"
AutoGenerateColumns="False" Font-Name="Verdana" DataKeyField="FullName"
OnItemDataBound="articleList_ItemDataBound"
OnDeleteCommand="articleList_DeleteFile">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name" />
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time"
ItemStyle-HorizontalAlign="Center"
DataFormatString="{0:d}" />
<asp:BoundColumn DataField="Length" HeaderText="File Size"
ItemStyle-HorizontalAlign="Right" DataFormatString="{0:#,##0 bytes}" />
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
CommandName="Delete" />
</Columns>
</asp:datagrid>
What is wrong with the cast?
Thanks,
Tom