stumac
07-03-2008, 12:49 AM
Hi Guys,
This is driving me nuts. I'm trying to delete a row from a gridview.
I have this code for the GridView;
<asp:GridView id="gv_auctions" EmptyDataText="You have no auction listings at present" OnRowEditing="gv_auctions_OnRowEditing" OnRowDeleting="gv_auctions_OnRowDeleting" datakeynames="auction_id" Width="760px" autogeneratecolumns="false" allowpaging="false" runat="server" BorderWidth="0px" BorderStyle="None">
<RowStyle BackColor="#ffffff" ForeColor="#444444" />
<AlternatingRowStyle BackColor="#eeeeee" ForeColor="#444444" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<div class="account_section_form_text" style="width:5%;">
No.
</div>
<div class="account_section_form_text" style="width:9%;">
Ref.
</div>
<div class="account_section_form_text" style="width:15%;">
Size
</div>
<div class="account_section_form_text" style="width:30%;">
Description
</div>
<div class="account_section_form_text" style="width:10%;">
Start Date
</div>
<div class="account_section_form_text" style="width:10%;">
End Date
</div>
<div class="account_section_form_text" style="width:8%;">
Reserve
</div>
<div class="account_section_form_text" style="width:8%;">
Buy Now
</div>
<div class="account_section_form_text" style="width:5%;">
&nbsp;
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="account_section_form_text" style="width:5%;">
<asp:Label runat="server" id="auction_id" text='<%# Eval("auction_id") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:9%;">
<asp:Label runat="server" id="auction_refno" text='<%# Eval("auction_refno") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:15%;">
<asp:Label runat="server" id="auction_adtype" text='<%# Eval("auction_ad_type") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:30%;">
<asp:Label runat="server" id="auction_description" text='<%# Eval("auction_description") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:10%;">
<asp:Label runat="server" id="auction_start" text='<%# Eval("startdate") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:10%;">
<asp:Label runat="server" id="auction_end" text='<%# Eval("enddate") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:8%;">
<asp:Label runat="server" id="auction_reserve" text='<%# Eval("auction_reserve") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:8%;">
<asp:Label runat="server" id="auction_buynow" text='<%# Eval("auction_buynow") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:5%;">
<asp:Button runat="server" Text="E" id="edit_auction_button" CommandName="Edit" CommandArgument='<%# Eval("auction_id") %>' cssClass="form_button_small" UseSubmitBehavior="false"></asp:Button>
<asp:Button runat="server" Text="X" id="delete_auction_button" CommandName="Delete" CommandArgument='<%# Eval("auction_id") %>' cssClass="form_button_small" UseSubmitBehavior="false"></asp:Button>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
OnRowDeleting Sub reads as follows;
Public Sub gv_auctions_OnRowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
Dim auction_id As Integer
auction_id = gv_auctions.DataKeys(e.RowIndex).Value
deleteAuction(auction_id)
End Sub
This works fine and dandy.
So I copied the code to another similar GridView I wanted which reads thus;
<asp:GridView id="gv_more_rates" datakeynames="rate_id" OnRowDeleting="gv_more_rates_onrowdeleting" Width="760px" ShowHeader="false" autogeneratecolumns="false" allowpaging="false" runat="server" BorderWidth="0px" BorderStyle="None">
<Columns>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<div class="account_section_form_text" style="text-transform:capitalize;">
<asp:Label runat="server" id="rates_name_label" text='<%# Eval("rates_name") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
<asp:Label runat="server" id="rates_colour_price_label" text='<%# Eval("rates_colour_price") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
<asp:Label runat="server" id="rates_mono_price_label" text='<%# Eval("rates_mono_price") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
<asp:Label runat="server" id="rates_type_area_label" text='<%# Eval("rates_type_area") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
&nbsp;
<asp:Label runat="server" id="rates_trim_size_label" text='<%# Eval("rates_trim_size") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
&nbsp;
<asp:Label runat="server" id="rates_bleed_area_label" text='<%# Eval("rates_bleed_area") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="freeform_wrapper" style="width:6%; text-align:center;">
<asp:Button runat="server" CommandName=""Delete" CommandArgument='<%# Eval("rate_id") %>'Text="X" id="delete_more_rates_button" UseSubmitBehavior="false" cssClass="form_button_small"></asp:Button>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
OnRowDeleting sub reads as follows;
Public Sub gv_more_rates_onrowdeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
Dim rateid As Integer
rateid = gv_more_rates.DataKeys(e.RowIndex).Value
deleteRate(rateid)
End Sub
The 2nd GridView won't fire the delete event. Why, why, why, why, why???
I've been on this 5 hours now, searching and changing stuff but to no avail. I've debugged in VS2005 and the click goes straight to page.postback coding. If I include the <asp:commandfield with showdeletebutton then this fires the ondeleting event.
But I thought having the CommandName of "Delete" did this anyway? Of course it does, because on the first Gridview (i a seperate aspx file), it does exactly this.
What the hell else can be on the page which stops the ondeleting event firing. It doesn't databind the GridView until the last line of the deleteRate Sub (code excluded as it merely deletes the rateid entry from the table - not getting this far so problem not here). I mention this because I read that databinding at the wrong time can upset the event flow sometimes.
Anybody more worthy than I who can understand why one GridView works and the copied one doesn't?
Regards,
Stuart
This is driving me nuts. I'm trying to delete a row from a gridview.
I have this code for the GridView;
<asp:GridView id="gv_auctions" EmptyDataText="You have no auction listings at present" OnRowEditing="gv_auctions_OnRowEditing" OnRowDeleting="gv_auctions_OnRowDeleting" datakeynames="auction_id" Width="760px" autogeneratecolumns="false" allowpaging="false" runat="server" BorderWidth="0px" BorderStyle="None">
<RowStyle BackColor="#ffffff" ForeColor="#444444" />
<AlternatingRowStyle BackColor="#eeeeee" ForeColor="#444444" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<div class="account_section_form_text" style="width:5%;">
No.
</div>
<div class="account_section_form_text" style="width:9%;">
Ref.
</div>
<div class="account_section_form_text" style="width:15%;">
Size
</div>
<div class="account_section_form_text" style="width:30%;">
Description
</div>
<div class="account_section_form_text" style="width:10%;">
Start Date
</div>
<div class="account_section_form_text" style="width:10%;">
End Date
</div>
<div class="account_section_form_text" style="width:8%;">
Reserve
</div>
<div class="account_section_form_text" style="width:8%;">
Buy Now
</div>
<div class="account_section_form_text" style="width:5%;">
&nbsp;
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="account_section_form_text" style="width:5%;">
<asp:Label runat="server" id="auction_id" text='<%# Eval("auction_id") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:9%;">
<asp:Label runat="server" id="auction_refno" text='<%# Eval("auction_refno") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:15%;">
<asp:Label runat="server" id="auction_adtype" text='<%# Eval("auction_ad_type") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:30%;">
<asp:Label runat="server" id="auction_description" text='<%# Eval("auction_description") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:10%;">
<asp:Label runat="server" id="auction_start" text='<%# Eval("startdate") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:10%;">
<asp:Label runat="server" id="auction_end" text='<%# Eval("enddate") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:8%;">
<asp:Label runat="server" id="auction_reserve" text='<%# Eval("auction_reserve") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:8%;">
<asp:Label runat="server" id="auction_buynow" text='<%# Eval("auction_buynow") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:5%;">
<asp:Button runat="server" Text="E" id="edit_auction_button" CommandName="Edit" CommandArgument='<%# Eval("auction_id") %>' cssClass="form_button_small" UseSubmitBehavior="false"></asp:Button>
<asp:Button runat="server" Text="X" id="delete_auction_button" CommandName="Delete" CommandArgument='<%# Eval("auction_id") %>' cssClass="form_button_small" UseSubmitBehavior="false"></asp:Button>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
OnRowDeleting Sub reads as follows;
Public Sub gv_auctions_OnRowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
Dim auction_id As Integer
auction_id = gv_auctions.DataKeys(e.RowIndex).Value
deleteAuction(auction_id)
End Sub
This works fine and dandy.
So I copied the code to another similar GridView I wanted which reads thus;
<asp:GridView id="gv_more_rates" datakeynames="rate_id" OnRowDeleting="gv_more_rates_onrowdeleting" Width="760px" ShowHeader="false" autogeneratecolumns="false" allowpaging="false" runat="server" BorderWidth="0px" BorderStyle="None">
<Columns>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<div class="account_section_form_text" style="text-transform:capitalize;">
<asp:Label runat="server" id="rates_name_label" text='<%# Eval("rates_name") %>'>
</asp:Label>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
<asp:Label runat="server" id="rates_colour_price_label" text='<%# Eval("rates_colour_price") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
<asp:Label runat="server" id="rates_mono_price_label" text='<%# Eval("rates_mono_price") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
<asp:Label runat="server" id="rates_type_area_label" text='<%# Eval("rates_type_area") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
&nbsp;
<asp:Label runat="server" id="rates_trim_size_label" text='<%# Eval("rates_trim_size") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="account_section_form_text" style="width:14%; text-align:center;">
<span>
&nbsp;
<asp:Label runat="server" id="rates_bleed_area_label" text='<%# Eval("rates_bleed_area") %>' cssclass="form_text_more_contacts">
</asp:Label>
</span>
</div>
<div class="freeform_wrapper" style="width:6%; text-align:center;">
<asp:Button runat="server" CommandName=""Delete" CommandArgument='<%# Eval("rate_id") %>'Text="X" id="delete_more_rates_button" UseSubmitBehavior="false" cssClass="form_button_small"></asp:Button>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
OnRowDeleting sub reads as follows;
Public Sub gv_more_rates_onrowdeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
Dim rateid As Integer
rateid = gv_more_rates.DataKeys(e.RowIndex).Value
deleteRate(rateid)
End Sub
The 2nd GridView won't fire the delete event. Why, why, why, why, why???
I've been on this 5 hours now, searching and changing stuff but to no avail. I've debugged in VS2005 and the click goes straight to page.postback coding. If I include the <asp:commandfield with showdeletebutton then this fires the ondeleting event.
But I thought having the CommandName of "Delete" did this anyway? Of course it does, because on the first Gridview (i a seperate aspx file), it does exactly this.
What the hell else can be on the page which stops the ondeleting event firing. It doesn't databind the GridView until the last line of the deleteRate Sub (code excluded as it merely deletes the rateid entry from the table - not getting this far so problem not here). I mention this because I read that databinding at the wrong time can upset the event flow sometimes.
Anybody more worthy than I who can understand why one GridView works and the copied one doesn't?
Regards,
Stuart