GridView question


D

Dave

I have a gridview that has Edit, Delete, and Select enabled. I'm
trying to run the below C# to prompt when deleting.

protected void DetailGridView_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = ((LinkButton)e.Row.Cells[0].Controls[1]);
l.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete the " +
DataBinder.Eval(e.Row.DataItem, "SOCDetail") + " SOC
Detail Entry?')");
}
}


When the control renders I'm getting the below Error:


Unable to cast object of type 'System.Web.UI.LiteralControl' to type
'System.Web.UI.WebControls.LinkButton'.


What am I doing wrong?


Thanks
 
Ad

Advertisements

D

Dave

I have a gridview that has Edit, Delete, and Select enabled.  I'm
trying to run the below C# to prompt when deleting.

protected void DetailGridView_RowCreated(object sender,
GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton l = ((LinkButton)e.Row.Cells[0].Controls[1]);
            l.Attributes.Add("onclick", "javascript:return " +
            "confirm('Are you sure you want to delete the " +
            DataBinder.Eval(e.Row.DataItem, "SOCDetail") + " SOC
Detail Entry?')");
        }
    }

When the control renders I'm getting the below Error:

Unable to cast object of type 'System.Web.UI.LiteralControl' to type
'System.Web.UI.WebControls.LinkButton'.

What am I doing wrong?

Thanks

Should have added this too:

<asp:GridView ID="DetailGridView" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False"
DataSourceID="DetailGridSqlDataSource"
DataKeyNames="ssocdID"
onprerender="DetailGridView_PreRender"
onrowcreated="DetailGridView_RowCreated"
onrowdatabound="DetailGridView_RowDataBound"
onrowdeleted="DetailGridView_RowDeleted"
onselectedindexchanged="DetailGridView_SelectedIndexChanged"
BackColor="White" AutoGenerateDeleteButton="True">
<Columns>
<asp:CommandField ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="ssocdID" HeaderText="ssocdID"
InsertVisible="False" ReadOnly="True"
SortExpression="ssocdID" Visible="False" />
<asp:TemplateField HeaderText="Client Detail"
SortExpression="SOCDetail">
<EditItemTemplate>
<table bgcolor="Silver">
<tr>
<td width="95px">
<b>Client Detail:&nbsp; </b>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("SOCDetail") %>'
Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<strong>Roll-up:</strong></td>
<td>
<asp:DropDownList ID="DropDownList1"
runat="server"

DataSourceID="DetailDropdownSqlDataSource" DataTextField="SOCDetail"
DataValueField="s" SelectedValue='<%#
Bind("socdID") %>'>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<strong>Display Order: </strong>
</td>
<td valign="top">
<asp:TextBox ID="DisplayOrderTextBox"
runat="server" Columns="5" MaxLength="5"
Text='<%# Bind("DisplayOrder") %>'></
asp:TextBox>
</td>
</tr>
</table>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="SOCDetailLabel" runat="server" Text='<
%# Bind("SOCDetail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
 

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

Top