How do I change to edit mode programmatically using vb code? My edit button is not switching the record to edit mode and I get the error:
The ListView 'ListView1' raised event ItemEditing which wasn't handled.. I am using a similar edit button on several FormViews and they work fine. I cannot figure out why it is not working on the ListView. I have searched the Net for a couple days
without success for ideas on how to access using VB coding. Does anyone have any ideas? Thanks.
If your ListView is bound to a data source control (e.g. DataSourceID="myDataSource"), then clicking a button with CommandName="Edit" will put the ListView in Edit mode and bind the data automatically. If you're not using a data source control, as it appears
is your case, then the ListView doesn't know how to retrieve the data. In this case you'll need to handle the ItemEditing/ItemUpdating/ItemCancelling/etc events and do wire everything up manually. For the ItemEditing case, you'll need something list this:
Don't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so everyone will know you have been helped.
Marked as answer by McGuire on Jul 31, 2008 01:53 PM
McGuire
Member
67 Points
161 Posts
Listview edit mode
Jul 30, 2008 02:15 PM|LINK
How do I change to edit mode programmatically using vb code? My edit button is not switching the record to edit mode and I get the error: The ListView 'ListView1' raised event ItemEditing which wasn't handled.. I am using a similar edit button on several FormViews and they work fine. I cannot figure out why it is not working on the ListView. I have searched the Net for a couple days without success for ideas on how to access using VB coding. Does anyone have any ideas? Thanks.
<asp:ListView ID="ListView1" runat="server" > <LayoutTemplate> <table><tr><td style="font-size:11px"></td></tr></table> <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder> </LayoutTemplate> <EditItemTemplate> <table style="width:100%"> <tr> <td align="right" colspan="3"> <asp:Button ID="btnSchoolsUpdate" OnClick="btnSchoolsUpdate_Click" runat="server" CommandName="Update" Text="Update" Width="50px" /> <asp:Button ID="btnSchoolsCancel" runat="server" CommandName="Cancel" Text="Cancel" Width="50px" /> </td> </tr> <tr> <td class="rust8">School Name:
</td> <td class="font8pt"> <asp:Textbox Visible="false" ID="Textbox29" runat="server" Text='<%#Bind("SchoolID")%>' /> <asp:Textbox ID="Textbox22" runat="server" Text='<%#Bind("SchoolName")%>' /> </td> <td> </td> </tr> <tr> <td class="rust8">School Address:
</td> <td class="font8pt"> <asp:Textbox ID="Textbox23" runat="server" Text='<%#Bind("SchoolAddress")%>' />, <asp:Textbox ID="Textbox24" runat="server" Text='<%#Bind("SchoolCity")%>' />, <asp:Textbox ID="Textbox25" runat="server" Text='<%#Bind("SchoolState")%>' /> <asp:Textbox ID="Textbox26" runat="server" Text='<%#Bind("SchoolZipCode")%>' /> </td> <td> </td> </tr> <tr> <td class="rust8">Major:
</td> <td class="font8pt"> <asp:Textbox ID="Textbox27" runat="server" Text='<%#Bind("Major")%>' /> <span class="rust8">Degree:</span> <asp:Textbox ID="Textbox28" runat="server" Text='<%#Bind("Degree")%>' /> </td> <td> </td> </tr> </table> </EditItemTemplate> <ItemTemplate> <table> <tr> <td class="rust8">School Name:
</td> <td class="font8pt"> <asp:Label Visible="false" ID="Label5" runat="server" Text='<%#Eval("SchoolID")%>' /> <asp:Label ID="Label22" runat="server" Text='<%#Eval("SchoolName")%>' /> </td> <td> </td> </tr> <tr> <td class="rust8">School Address:
</td> <td class="font8pt"> <asp:Label ID="Label23" runat="server" Text='<%#Eval("SchoolAddress")%>' />, <asp:Label ID="Label24" runat="server" Text='<%#Eval("SchoolCity")%>' />, <asp:Label ID="Label25" runat="server" Text='<%#Eval("SchoolState")%>' /> <asp:Label ID="Label26" runat="server" Text='<%#Eval("SchoolZipCode")%>' /> </td> <td> </td> </tr> <tr> <td class="rust8">Major:
</td> <td class="font8pt"> <asp:Label ID="Label27" runat="server" Text='<%#Eval("Major")%>' /> <span class="rust8">Degree:</span> <asp:Label ID="Label28" runat="server" Text='<%#Eval("Degree")%>' /> </td> <td> </td> </tr> <tr> <td colspan="3" align="right" style="width:700px"> <asp:Button ID="btnSchoolsEdit" runat="server" CommandName="Edit" Text="Edit" Width="50px" /> </td> </tr> </table> </ItemTemplate> <ItemSeparatorTemplate> <div style="height:0px;border-top:groove 1px #cccccc"></div> </ItemSeparatorTemplate> <EmptyDataTemplate>No records found.
</EmptyDataTemplate> </asp:ListView>J.R.R. Tolkien
agolden
Star
7893 Points
1060 Posts
Re: Listview edit mode
Jul 31, 2008 02:25 AM|LINK
Hi McGuire,
If your ListView is bound to a data source control (e.g. DataSourceID="myDataSource"), then clicking a button with CommandName="Edit" will put the ListView in Edit mode and bind the data automatically. If you're not using a data source control, as it appears is your case, then the ListView doesn't know how to retrieve the data. In this case you'll need to handle the ItemEditing/ItemUpdating/ItemCancelling/etc events and do wire everything up manually. For the ItemEditing case, you'll need something list this:
protected void ListView1_ItemEditing(object sender, ListViewEditEventArgs e) { ListView1.EditIndex = e.NewEditIndex; ListView1.DataSource = SomeData; ListView1.DataBind(); }Hope that helps.
Aaron
McGuire
Member
67 Points
161 Posts
Re: Listview edit mode
Jul 31, 2008 03:38 PM|LINK
Just what I was looking for. Thanks. It is working now.
Also found another post that takes it a bit further for anyone who may need it: http://forums.asp.net/p/1256465/2336693.aspx
J.R.R. Tolkien