Wednesday, March 21, 2012

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.

No comments:

Post a Comment