473,776 Members | 1,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.datas ource = nothing and gridviewx.datas ourceid = nothing
before setting it to gridviewx.datas ource = 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 7244
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" ContentPlaceHol derID="ContentP laceHolder1"
runat="Server">
<br />
<br />
<asp:CheckBox ID="AllCheck" runat="server" AutoPostBack="T rue" />
<br />
<br />
<asp:GridView ID="RouteGridVi ew" runat="server"
AllowPaging="Tr ue" AllowSorting="T rue"
AutoGenerateCol umns="False" DataKeyNames="d estId"
SkinID="GridVie w"
DataSourceId="s 1" OnRowDeleting=" myrowdeleting"
OnRowDeleted="m yrowdeleted">
<Columns>
<asp:CommandFie ld ButtonType="Ima ge"
ShowDeleteButto n="true" ShowSelectButto n="True"
SelectImageUrl= "../App_Themes/WinXP_Silver/Images/edit.gif"
DeleteImageUrl= "../App_Themes/WinXP_Silver/Images/delete.gif"/>
<asp:BoundFie ld DataField="Plan Code"
ItemStyle-Width="20" HeaderText="Pla n Code" SortExpression= "Plancode"
/>
<asp:BoundFie ld DataField="Dest Code"
ItemStyle-Width="20" HeaderText="Des t Code" SortExpression= "routeCode"
/>
<asp:BoundFie ld DataField="rout eCode"
ItemStyle-Width="20" HeaderText="Rou te Code"
SortExpression= "routeCode" />
</Columns>
</asp:GridView>

<asp:SqlDataSou rce ID="s1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:RTEConnectio nString %>"
SelectCommand=" select * from gen_routeinfo_v w where
routecode = 'JCP'"
DeleteCommand=" delete route where destid=@destId; delete
destination where destid=@destid"
>
<DeleteParamete rs>
<asp:Paramete r Name="destId" />
</DeleteParameter s>

</asp:SqlDataSour ce>

<asp:SqlDataSou rce ID="s2" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:RTEConnectio nString %>"
SelectCommand=" select * from gen_routeinfo_v w where
routecode = 'JCP'"
DeleteCommand=" delete route where destid=@destId; delete
destination where destid=@destid" >
<DeleteParamete rs>
<asp:Paramete r Name="destId" />
</DeleteParameter s>
</asp:SqlDataSour ce>
<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.P age
Protected Overrides Sub OnPreRender(ByV al e As EventArgs)
If IsPostBack Then
RouteGridView.D ataSourceID = Nothing
RouteGridView.D ataSource = Nothing
If AllCheck.Checke d Then
RouteGridView.D ataSource = s2
Else
RouteGridView.D ataSource = s1
End If
RouteGridView.D ataBind()
End If
End Sub
Protected Sub Allcheck_Checke dChanged(ByVal sender As Object, ByVal
e As System.EventArg s) Handles AllCheck.Checke dChanged
RouteGridView.D ataBind()
End Sub

Protected Sub myRowDeleted(By Val sender As Object, ByVal e As
GridViewDeleted EventArgs) Handles RouteGridView.R owDeleted
If e.Exception IsNot Nothing Then
StatusLabel.Tex t = e.Exception.ToS tring.Substring (0, 250) +
"<br>" + StatusLabel.Tex t
e.ExceptionHand led = True
Else
StatusLabel.Tex t = "Record Deleted"
RouteGridView.D ataBind()
End If
End Sub

Protected Sub myRowDeleting(B yVal sender As Object, ByVal e As
GridViewDeleteE ventArgs) Handles RouteGridView.R owDeleting
'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
10443
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 this control in the list of objects in odeBehind page. GridView1 and DropDownList1 are bound to TWO DIFFERENT tables (DataSources). The last column of each row in the GridView is shown as a DropDownList. I want to use the SelectedIndexChanged ...
0
1031
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 relationship between datasources and gridviews? when I switch datasources - deletes don't happen and I get erros like this when I try to page or sort:
2
11638
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 SelectButton), the selected record is shown in the DetailsView, which is correct - however, when I choose "Update" on the DetailsView I am presented with the EditItemTemplate which contains the first record in the DetailsDataSource. The code...
11
4080
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, CrtdUser and Date And Edit and Delete buttons
3
311
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 columns. These are all for data entry and although I am populating the dropdown list boxes with an objectdatasource so the user can provide a selection, I am not binding the gridview to anything. The command buttons again are for the user to be...
0
1595
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 EditTemplate). None of the other columns get updated except for that one. Any ideas? The only column that is not able to be updated is the ID column, but that isn't even in the table. <asp:GridView ID="EternityNewsMemberList" runat="server"...
0
4282
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 want to have my parameter names in those methods have to be "original_Parametername" or even if I change the OldValuesParameterFormatString to get rid of the "original" I would still have just "Parametername". I think most people user parameters...
0
881
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 column for role Dim roleNameColumn As New TemplateField()
3
7391
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 was planning to split into one for each accordion when I finally get one UpdatePanel working). I guess it is probably something of which I am ignorant. upFull = (UpdatePanel) this.Page.FindControl("upFull"); // the previous line returns null so...
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8952
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.