473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

gridview switching datasources in the codebehind. ... Delete no longer happens.

I've got a gridview that does not have a datasourceid assigned in the
markup.

I'd like to switch between two datasources in the codebehind. when I do
switch, I first reset the the
gridviewx.datasource = nothing and gridviewx.datasourceid = nothing
before setting it to gridviewx.datasource = newdatasoruceid and then
rebinding.

All appears to work well until I try to excute a delete command that
otherwise works great when the datasource is set fixed in the markup.
Except now, nothing happens.

I've tried adding ondeleting and ondeleted, the code never gets to
ondeleted when I switch datasources in the codebehind.

I there something else I need to set, or are things broken beyond
repair at that point. If so, shame as the potential of muliple
datasources offers a lot of options that help simplify sql.

Thanks for any help or information.

Nov 21 '06 #1
3 7213
Hello jobs!

Thanks for posting a topic.

It could be difficult to understand what actually you are trying to
accomplish.

Kindly paste the code here so that the problem could be resolved.

Regards,
Mohsin Rizvi

Nov 21 '06 #2
have a simple gridview that I need to switch datasources on in the
codebehind. Everything works great with it until I switch. For example,
Delete, does not actually delete - it calls the on ondeleting sub, but
never actually deletes. If set the datasource in the markup and don't
switch, delete works fine.

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
runat="Server">
<br />
<br />
<asp:CheckBox ID="AllCheck" runat="server" AutoPostBack="True" />
<br />
<br />
<asp:GridView ID="RouteGridView" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="destId"
SkinID="GridView"
DataSourceId="s1" OnRowDeleting="myrowdeleting"
OnRowDeleted="myrowdeleted">
<Columns>
<asp:CommandField ButtonType="Image"
ShowDeleteButton="true" ShowSelectButton="True"
SelectImageUrl="../App_Themes/WinXP_Silver/Images/edit.gif"
DeleteImageUrl="../App_Themes/WinXP_Silver/Images/delete.gif"/>
<asp:BoundField DataField="PlanCode"
ItemStyle-Width="20" HeaderText="Plan Code" SortExpression="Plancode"
/>
<asp:BoundField DataField="DestCode"
ItemStyle-Width="20" HeaderText="Dest Code" SortExpression="routeCode"
/>
<asp:BoundField DataField="routeCode"
ItemStyle-Width="20" HeaderText="Route Code"
SortExpression="routeCode" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="s1" runat="server"
ConnectionString="<%$ ConnectionStrings:RTEConnectionString %>"
SelectCommand="select * from gen_routeinfo_vw where
routecode = 'JCP'"
DeleteCommand="delete route where destid=@destId;delete
destination where destid=@destid"
>
<DeleteParameters>
<asp:Parameter Name="destId" />
</DeleteParameters>

</asp:SqlDataSource>

<asp:SqlDataSource ID="s2" runat="server"
ConnectionString="<%$ ConnectionStrings:RTEConnectionString %>"
SelectCommand="select * from gen_routeinfo_vw where
routecode = 'JCP'"
DeleteCommand="delete route where destid=@destId;delete
destination where destid=@destid">
<DeleteParameters>
<asp:Parameter Name="destId" />
</DeleteParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:Label ID="StatusLabel" runat="server" Height="109px"
Text="Label" Width="484px"></asp:Label><br />
<br />
<br />

</asp:Content>


.... codebehind :
Partial Class Delete
Inherits System.Web.UI.Page
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
If IsPostBack Then
RouteGridView.DataSourceID = Nothing
RouteGridView.DataSource = Nothing
If AllCheck.Checked Then
RouteGridView.DataSource = s2
Else
RouteGridView.DataSource = s1
End If
RouteGridView.DataBind()
End If
End Sub
Protected Sub Allcheck_CheckedChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles AllCheck.CheckedChanged
RouteGridView.DataBind()
End Sub

Protected Sub myRowDeleted(ByVal sender As Object, ByVal e As
GridViewDeletedEventArgs) Handles RouteGridView.RowDeleted
If e.Exception IsNot Nothing Then
StatusLabel.Text = e.Exception.ToString.Substring(0, 250) +
"<br>" + StatusLabel.Text
e.ExceptionHandled = True
Else
StatusLabel.Text = "Record Deleted"
RouteGridView.DataBind()
End If
End Sub

Protected Sub myRowDeleting(ByVal sender As Object, ByVal e As
GridViewDeleteEventArgs) Handles RouteGridView.RowDeleting
'RouteGridView.DataBind()
End Sub

End Class

Nov 21 '06 #3
Apparently switching datasources in codebehind messes up other things
like sorting and paging too...

The GridView 'RateGridView' fired event Sorting which wasn't handled.

Unless somebody knows how to do this I will need to duplicate the
grids and have one for every source.

Nov 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nam | last post by:
I have a DropDownList control in a TemplateField inside my GridView How do I access this control’s SelectedIndexChanged event in codeBehind page? I don’t see the ID “DropDownList1” of...
0
by: jobs | last post by:
Is there a correct way to change the datasourceId of a gridview in codebehind so that things like sorting, paging and deleting actually work? Or will have have to have one one to one...
2
by: mike | last post by:
I have a page with a LoginView which contains a Gridview and a DetailsView, each in its own UpdatePanel The problem that I am experiencing is that when I select a record in the Gridview (using a...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview with several template columns and a few command button columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and column 4 is a text box, followed by command button...
0
by: Andy B | last post by:
I have a GridView with a LINQDataSource attached to it. My code in the aspx markup is below. I need to know why only the checkbox field for the activated column is getting updated (the...
0
by: steve | last post by:
I have been fighting with trying to update a GridView for a while. I don't want to use the "built-in" way to do it because I am using business layer methods for updating and deleteing and I don't...
0
by: gamesforums | last post by:
Hi! I need to add a delete button in a column for my GridView. It has to be done in the codebehind. Here's my code so far: Protected WithEvents roleList As New GridView 'create templatefield...
3
by: stoogots2 | last post by:
I'm wondering why I can't find the updatepanel control in my codebehind file Page_Load event. I have several gridviews, each in their own accordion control/pane, all inside an updatepanel (which I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.