Monday, March 26, 2012

UpdatePanel & GridView Event

Hi,

I have a GridView inside an UpdatePanel. How can I update that panel after (at the end) the RowUpdating event of the GridView?

I've tried many things, but none solved my problem yet.

What do you mean Update the panel? If the gridview is inside the update panel, then anything that is inside on the update panel that is modified durring the events will be changed after the partail postback. Now the RowUpdating event is fired before the datasource is updated, so technically there is no change to the gridview after this event is fired. Now the RowUpdated event, this is fired AFTER the datasource has been updated (or to be correct, after the datasource has attempted to change). You can put a GridView1.DataBind() at the end of this event to force a gridview update its rows.

-Alan


On the properties tab for the update panel click on Triggers. A box will pop-up click the add button. There will be a dropdownlist for the ControlID, select the GridView that you want to trigger the update. There will be a dropdownlist for the EventName, select RowUpdating. Click OK and it should work.


You could use the .Update() method of the UpdatePanel you want to refresh.


You have to use UpdatePanel.Update() method to update the contents inside UpdatePanel


I've tried before the Update() method and the triggers, but they don't work.

I'm using this GridView:

http://www.aspdotnetcodes.com/Simple_Insert_Update_Delete_GridView_Sample.aspx

So, what I want is to update the UpdatePanel after a row edit, wich hapens on the RowUpdating Event. I want to update it because I have a label outside the GridView with the sum of one of the columns of the GridView, and without the update it only changes the value when I hit refresh on the browser or when I move to another page and then return.


Is the label inside the ContentTemplate of the updatepanel?


bolinc:

Is the label inside the ContentTemplate of the updatepanel?

NoEmbarrassed

I forgot to put the label inside the ContentTemplate tags of the UpdatePanel.

It's always something so stupid...

Thanks bolinc Yes


I think this might solve your problem.

The gridview has to call the onRowUpdated method. Don't forget that the data source also has to be within the update panel (i left mine out b/c it took up too much space). the method it calls is simple. Don't forget to set the dataKeyNames on the gridview. I forget that all the time. and i just put those extra two labels in to test that the update was only occurring in the panel b/c i didn't have anything else on the page.

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"AutoGenerateEditButton="True"

DataKeyNames="SPDdifference,biMonthlySalary"DataSourceID="SqlDataSource1"OnRowUpdated="Display_Message">

<Columns>

<asp:BoundFieldDataField="ID"HeaderText="ID"InsertVisible="False"ReadOnly="True"

SortExpression="ID"/>

<asp:BoundFieldDataField="ssan"HeaderText="ssan"SortExpression="ssan"/>

<asp:BoundFieldDataField="fName"HeaderText="fName"SortExpression="fName"/>

<asp:BoundFieldDataField="lName"HeaderText="lName"SortExpression="lName"/>

<asp:BoundFieldDataField="SPDdifference"HeaderText="SPDdifference"SortExpression="SPDdifference"/>

<asp:BoundFieldDataField="biMonthlySalary"HeaderText="biMonthlySalary"SortExpression="biMonthlySalary"/>

</Columns>

</asp:GridView>

<br/>

<asp:LabelID="Label1"runat="server"Width="536px"></asp:Label><br/>

<asp:LabelID="Label3"runat="server"Text="Label"Width="528px"></asp:Label>

</ContentTemplate>

</asp:UpdatePanel>

==========================================================================================

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

Label2.Text =Date.Now

Label3.Text =Date.Now

EndSub

Sub Display_Message(ByVal SrcAsObject,ByVal ArgsAs GridViewUpdatedEventArgs)

Dim spAsDecimal = Args.Keys("SPDdifference")

Dim biAsDecimal = Args.Keys("biMonthlySalary")

Dim totalAsDecimal = bi - sp

Label1.Text ="here's spd " & total

EndSub


sorry to have given such a detailed answer to such a simple question. Zip it!

i have been bored this morning!

No comments:

Post a Comment