Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do you need event on GridView if it is fired 2

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I have a GridView where I am deleting a row with a link button.

But I am getting an error:

[HttpException (0x80004005): The GridView 'GridView1' fired event RowDeleting which wasn't handled.]
System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs e) +1483085
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +637

My GridView is:

Code:
<asp:GridView visible="False" 
	border="1"		
	id="GridView1" 
	runat="server" 
	AutoGenerateColumns="False" 
	GridLines="None"
	ShowFooter="true"
        OnRowCreated="GridView1_RowCreated" 
	OnRowDataBound="GridView1_RowDataBound"
	OnRowCommand="DataInsert"
	onEditCommand="DataEdit"
	onCancelCommand="DataCancel"
	onUpdateCommand="DataUpdate">

I have no OnRowDeleting on my GridView, so why would I get an error?

Thanks,

Tom
 


Maybe look in the RowCommand event and see if there is a reference like if e.CommandName = "Delete". If there is, you'll need to either create a stub for the OnRowDeleting event or change the name to something else.


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Here is the whole markup. It was originally a DataGrid.

I do have the line that was mentioned in the previous reply in my code behind:

if (e.CommandName == "Delete")
{

Why would that force me to have an event handler for RowDeleting?

Code:
<asp:GridView visible="False" 
	border="1"		
	id="GridView1" 
	runat="server" 
	AutoGenerateColumns="False" 
	GridLines="None"
	ShowFooter="true"
        OnRowCreated="GridView1_RowCreated" 
	OnRowDataBound="GridView1_RowDataBound"
	OnRowCommand="DataInsert"
	onEditCommand="DataEdit"
	onCancelCommand="DataCancel"
	onUpdateCommand="DataUpdate">

<AlternatingRowStyle BorderWidth="0px" BorderStyle="None" BorderColor="White" BackColor="linen"/>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"/>

<Columns>
	<asp:TemplateField HeaderText="Answer">
		<ItemTemplate>
			<asp:Label id="lblAnswer" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Answer") %>'>
			</asp:Label>
		</ItemTemplate>
		<FooterTemplate>
			<asp:TextBox id="txtAnswerFooter" columns="60" MaxLength="250" runat="server"></asp:TextBox>
		</FooterTemplate>
		<EditItemTemplate>
			<asp:textbox id="txtAnswer"  columns="60" MaxLength="250" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Answer") %>'>
			</asp:textbox>
		</EditItemTemplate>
	</asp:TemplateField>
	<asp:TemplateField visible="false">
		<ItemTemplate>
			<asp:Label id="lblQuestionUnique" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
			</asp:Label>
		</ItemTemplate>
		<FooterTemplate>
			<asp:Label id="lblQuestionUniqueFooter" runat="server">
			</asp:Label>
		</FooterTemplate>
	</asp:TemplateField>
	<asp:TemplateField ItemStyle-Width="100%" visible="false">
		<ItemTemplate>
			<asp:Label id="lblAnswerUnique" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AnswerUnique") %>'>
			</asp:Label>
		</ItemTemplate>
		<FooterTemplate>
			<asp:Label id="lblAnswerUniqueFooter" runat="server">
			</asp:Label>
		</FooterTemplate>
	</asp:TemplateField>
    <asp:TemplateField ItemStyle-Width="10%" ItemStyle-HorizontalAlign="center">
        <ItemTemplate>
            <asp:RadioButton ID="myRadioButton" AutoPostBack="True" OnCheckedChanged="MyRadioButton1_CheckedChanged" runat="server"/>
            <asp:CheckBox ID="myCheckBox" AutoPostBack="True" GroupName="tom" OnCheckedChanged="MyRadioButton1_CheckedChanged" runat="server"/>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:CommandField EditText="Edit"  visible="true" itemstyle-width="10%"
		ButtonType="Link" UpdateText="Update" CancelText="Cancel" />            
	<asp:TemplateField ItemStyle-Width="45" FooterStyle-Width="45">
		<ItemTemplate>
			<asp:LinkButton CommandName="Delete" CommandArgument='<%# Container.DataItemIndex %>' Text="Delete" ID="btnDelete" Runat="server" />
		</ItemTemplate>
		<FooterTemplate>
			<asp:LinkButton CommandName="Insert" CommandArgument='<%# Container.DataItemIndex %>' Text="Add" ID="btnAdd" Runat="server" />
		</FooterTemplate>
	</asp:TemplateField>
	<asp:TemplateField ItemStyle-Width="45">
		<itemtemplate>
			<asp:RadioButton CommandName="Move" ID="rowSelected" AutoPostBack="true" OnCheckedChanged="SetMoveGrid_Click" runat="server" /> 
		</itemtemplate>
    </asp:TemplateField>
</Columns>
</asp:GridView>

Thanks,

Tom
 


<asp:LinkButton [red]CommandName="Delete"[/red] CommandArgument='<%# Container.DataItemIndex %>' Text="Delete" ID="btnDelete" Runat="server" />



Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Looks like Mark may be correct here. Try changing your commandname to something like "myDelete". Then change your If statement.
That should work.
 
Does that mean it is hard coded?

Tom
 
Does that mean what is hardcoded?
It means that the gridview is looking for reserved words such as "Delete", "Update", "Cancel", "Select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top