Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > gridview switching datasources in the codebehind. ... Delete no longer happens.

Reply
Thread Tools

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

 
 
jobs
Guest
Posts: n/a
 
      11-21-2006
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.

 
Reply With Quote
 
 
 
 
Mohsin Rizvi
Guest
Posts: n/a
 
      11-21-2006
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

 
Reply With Quote
 
 
 
 
jobs
Guest
Posts: n/a
 
      11-21-2006
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>
<asparameter 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>
<asparameter 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

 
Reply With Quote
 
jobs
Guest
Posts: n/a
 
      11-21-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView made by different datasources tsaprout ASP .Net 0 07-30-2008 11:52 AM
filling the same gridview wid from different datasources Shanksluvsuall ASP .Net 0 03-14-2008 11:27 AM
FormView and GridView with DataSources =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= ASP .Net 0 02-01-2007 09:09 AM
Gridview with changing Datasources in code - some things don't work jobs ASP .Net 0 11-21-2006 05:05 PM
Programs taking longer and longer to start up. Help please. Goforit Computer Information 9 07-25-2004 06:34 AM



Advertisments