Click here to Skip to main content
15,885,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all, does any one give me reference for how to handle listview events when listview is binding using DataSource property in codebehind. I implement inserting,updating etc. but when i click on edit it does not work correctly.
ASP.NET
<asp:ListView ID="listAllCourses" runat="server" InsertItemPosition="LastItem" DataKeyNames="BatchID"                                      OnItemCreated="listAllCourses_ItemCreated"                                    oniteminserting="listAllCourses_ItemInserting"                                     onitemediting="listAllCourses_ItemEditing">
<ItemTemplate>
                                        <tr>
                                            <td>
                                                <asp:Label runat="server" ID="lblId"><%#Container.DataItemIndex+1 %></asp:Label>
                                            </td>
                                            <td>
                                                <asp:Label runat="server" ID="lblName"><%#Eval("Name") %></asp:Label>
                                            </td>
                                            <td>
                                                <asp:Label runat="server" ID="lblType"><%#Eval("TotalSeats")%></asp:Label>
                                            </td>
                                            <td>
                                                <asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <td>
                                            <asp:Label runat="server" ID="lblId"><%#Container.DataItemIndex+1 %></asp:Label>
                                        </td>
                                        <td>
                                            <asp:Label runat="server" ID="lblName"><%#Eval("Name") %></asp:Label>
                                        </td>
                                        <td>
                                            <asp:TextBox ID="txtUpCtype" runat="server" Width="100px" Text='<%#Eval("TotalSeats") %>'></asp:TextBox>
                                        </td>
                                        <td>
                                            <asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update">Update</asp:LinkButton>
                                            <asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete">Delete</asp:LinkButton>
                                            <asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
                                        </td>
                                        </tr>
                                    </EditItemTemplate>
</asp:ListView>
Posted
Comments
Kornfeld Eliyahu Peter 23-Jul-14 2:50am    
"does not work correctly" is a very poor definition of problem!
Please be more specific! What are you expecting? What happening in reality? There are errors? Where?
[no name] 23-Jul-14 3:27am    
when i click on edit..the 'totalseats' label suppose to be change to textbox..but it doen't
Kornfeld Eliyahu Peter 23-Jul-14 3:48am    
I can't see you edit button in the code sample you posted...It should be like this:
<asp:Button ID="btnEdit" runat="server" CommandName="Edit" Text="Edit">Cancel
It may be that you are using LinkButton?
[no name] 23-Jul-14 3:51am    
it is in ItemTemplate
Sulabh Agarwal 23-Jul-14 5:34am    
You can use the EditItemTemplate for making the labels as textbox.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900