Showing posts with label row. Show all posts
Showing posts with label row. Show all posts

Wednesday, March 28, 2012

UpdatePanel - Single GridView row

I have a GridView where the database query is rather slow. I would like to use the UpdatePanel when editing a single row. Placing the entire grid inside of an UpdatePanel causes the entire grid to bind to the data source which takes several seconds. Is there a way to only update the row being edited by placing the UpdatePanel inside of the ItemTemplate or something like that? I haven't been able to figure this out. I'm sure I've seen an example of something similar to this but can't find it.

Thanks for any help.

You can add UpdatePanel to ItemTemplate/EditTemplate but you will end up with more HTML and javascript on client side.

I would rather focus on finding out why the query takes longer to execute? and fixing it.

Use serverside paging, caching to speed it up. Take a look at ScottGu's Weblog:http://weblogs.asp.net/scottgu/archive/2006/03/22/Efficient-Data-Paging-and-Sorting-with-ASP.NET-2.0-and-SQL-2005.aspx

Saturday, March 24, 2012

UpdatePanel and database

Hi there.

Is it possible to use UpdatePanel with SqlDependency to update a gridview or other bounded control whenever a row is added to a table? Or the update panel triggers collection only works with controls?

Thanks in advance,
P. Conde

Hey Pedro,

About a year ago I responded to two posts regarding the same kind of topic you are talking about. Currently there is not implementation inherent to ASP.NET to accomplish your scenario. I myself was also looking to accomplish what you were trying to do as well.

The only solution that I could come up with is the solution I have listed in the following links. I have recently implemented this solution in a Proof-Of-Concept (POC) kind of way. There are server technologies out there that are not .NET and support server push technology. Specifically do a search on google for "Comet" it's a phrase that was coined by one of the creators of the DojoToolkit. Also check out Meebo.com they have a great example of implementing a service with no page refreshes simply data pushing.

The only thing I left out in the posts below was that in order to get the flash client to connect you have to put a crossdomain.xml on the server in the root inetpub folder (wwwroot).

Other than that I have implemented the Windows service to listen on a specific port, and flash connects from the browser to the server and port and passes and receives XML. Then through the External Interface it can update the page. The Windows Service can listen on a SqlCommand with the SqlDependency object for changes in the current query.

You could use the SqlDependencyCache object but that would only work for when you do a postback. All it does is invalidate the cache so that the data has to be loaded from the Sql Server again. Anyhow good luck with you project.

The Solution
http://forums.asp.net/thread/1366004.aspx
SqlDepedency Question
http://forums.asp.net/thread/1336290.aspx

JoeWeb


I have set all the SqlDependency issues and I can see by debugging that it is workin when a table changes (row inserted/deleted/...). I'm using an event in a webusercontrol as a trigger for the update panel. Even if I use label or textbox controls getting some data in a sql database, the asyncpostback doesnt work... If I use a button at the updatepanel and click on it, the grid is updated...

I have seen the video "#4 | How Do I: Implement Dynamic Partial-Page Updates with ASP.NET AJAX?" and I'm following the leads in it... Shouldn't this be working?!

Anyone has solution for this?!

P. Conde


As I have previously stated this is not possible. The best possible solution would to be implementing a custom solution.

The SqlDependency object sets up an new Notification Stored Procedure along with a Service Broker to channel the request back to the client.

However in an HTTP scenario the Service Broker cannot invoke a page refresh... and therefore it is "IMPOSSIBLE" to make this a viable solution. HTTP doesn't allow there to be a server push without it being hosted on a server that has "Comet" technology. Again your best bet is to implement a custom solution.

Even though it's wrapped in Ajax it doesn't mean it keeps an open connection... it's still doing a postback when you hit that button.

Good Luck!
JoeWeb

Wednesday, March 21, 2012

UpdatePanel and GridView

I have a GridView that updates a FormView, ive now added the UpdatePanel around the FormView.

When I select a row from the Gridview the FormView Displays the details inside the FormView..great, but......

I have paging enabled on the Gridview so when I click page 2 i dont see the new list in the GridView, how do I fix this?

<-- GridView1 -->

<

MsAjax:ScriptManagerid="ScriptManager"runat="server"EnablePartialRendering="true"/><MsAjax:UpdatePanelID="ID1"runat="server"><ContentTemplate>

<--FORMVIEW -->

</

ContentTemplate>

<Triggers>

<MsAjax:AsyncPostBackTriggerControlID="GridView1"EventName="RowCommand"/>

</Triggers></MsAjax:UpdatePanel>

Hi

Putting UpdatePanel around formview should not effect GridView's Paging. If you have paging enabled it should display you the next records in the table. Does it actually select the page No. 2. or it stays on 1.

Amit


If you want to see the updated list (from the FormView), you must put the GridView also in a UpdatePanel.
Can be in the same UpdatePanel where the FormView is in, or in a new UpdatePanel.
If he's in a other Updatepanel, be sure to attach a trigger to the FormView to it.

(i'm not sure if this is what youre problem was, but you never know..)

UpdatePanel and GridView Problem.(selectedindexchanged doesnt work!)

Hi everyone, I've ran into an updatepanel problem. In my GridView I have a select button which takes the selected row info and puts it into a FormView. I put the Gridview inside an UpdatePanel but now when I click on the select button, no info goes to formview. However without the updatepanel it works ok. Does anyone know why this happens. I include the code below and the formview is just a simple formview.

<ajax:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:GridViewID="GridView1"runat="server" AutoGenerateColumns="False"DataKeyNames="ID"DataSourceID="ap"OnDataBound="GridView1_DataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >

<Columns>
<asp:BoundFieldDataField="Class"/>
<asp:BoundFieldDataField="Sector"/>
<asp:BoundFieldDataField="Name"/>
<asp:CommandFieldButtonType="Image"SelectImageUrl="~/images/extras/preview.png"ShowSelectButton="True"/>
</Columns> </asp:GridView>
</ContentTemplate>
</ajax:UpdatePanel>

<asp:SqlDataSourceID="ap"runat="server"ConnectionString="<%$ ConnectionStrings: ConnectionString%>"
SelectCommand="SELECT * FROM group >
</asp:SqlDataSource>

ProtectedSub GridView1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles GridView1.SelectedIndexChanged

FVTransaction.ChangeMode(FormViewMode.Insert)
Dim ClassAsString = GridView1.SelectedRow.Cells(0).Text
Dim SectorAsString = GridView1.SelectedRow.Cells(1).Text
Dim NameAsString = GridView1.SelectedRow.Cells(2).Text

Dim PClassAs TextBox =CType(FVTransaction.FindControl("FVClass"), TextBox)
Dim PSectorAs TextBox =CType(FVTransaction.FindControl("FVSector"), TextBox)
Dim PNameAs TextBox =CType(FVTransaction.FindControl("FVName"), TextBox)

PClass.Text = Class.ToString
PSector.Text = Sector.ToString
PName.Text = Name.ToString

EndSub

Thanks for your help.

wow, your formatting makes it really hard to keep track of where stuff is...I couldn't find the formview on there.

anyway, if I had to guess, i'd say that your formview isn't in an updatepanel. Try putting it in one (the same or different, shouldnt' matter) and that should do the trick.


sorry for the formatting, when I paste it, it looked great but then I don't know what happened. I fixed it now.

For your question, Unfortunatelly I can't have the formView inside the same panel as GridView because of the page design template. Is there an another work around?

Thanks


Thank you for your suggestion. I thought I need to have the GridView and FormView in the same updatepanel. But When I put formview another updatepanel, it worked.

Thanks


Glad I could help.

Updatepanel and Literal control

I have a customer search dialog.

The user selects a row from the grid and Literal control is updated with Javascript which should close the dialog should then close and a customer account number field on the parent page should be updated.

This all works until I put the grid inside an Updatepanel - then selecting a row does cause the Literal cojntrol to be updated.

From some testing it seems that the Updatepanel is the cause of the problem - its not letting the grid update the Literal control when it is outside the Updatepanel (And when the Literal control is inside the Updatepanel - updating it doesnt do anything)

I think I can update the Literal control using something like Page.FindControl. However, I have been told that this breaks encapsulation and that I should raise an event from the grid and have the Literal control grab it.

Is raising an event the best solution ?

Updating a Literal with script used to be a great tool for me when I was doing 1.1 development, and posting back all of the time. Setting it with script won't cause the page to execute it unless the page were reloaded.

In this example, you should be fine with removing the UpdatePanel for a dialog box scenario, as a postback will simply cause the dialog window to close.


But I want the UpdatePanel on the dialog box - the user could run a number of searches for a customer before selecting one (Dont think I mentioned that) so I dont want to keep refreshing the whole thing if I can avoid it.
No, you didn't mention that. :)