Wednesday, 8 October 2014

How to Using ListView in Asp.Net c#

LISTVIEW 





Template are used in ListView :

    1. AlternatingItemTemplate
    2. EditItemTemplate
    3. EmptyDataTemplate
    4. InsertItemTemplate
    5. ItemTemplate
    6. SelectedItemTemplate



                         Html Coding


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" DataSourceID="SqlDataSource1">
            <AlternatingItemTemplate>
                <tr style="background-color#FFFFFF;color#284775;">
                    <td>
                      <asp:Label ID="IdLabel" runat="server" 
Text='<%# Eval("Id"%>' />
                    </td>
                    <td>
                   <asp:Label ID="nameLabel" runat="server"
 Text='<%# Eval("name"%>'/>
                    </td>
                    <td>
                       <asp:Label ID="ageLabel" runat="server" Text='<%# Eval("age"%>'/>
                    </td>
                    <td>
                        <asp:Label ID="mobileLabel"
 runat="server"
 Text='<%# Eval("mobile"%>' />
                    </td>
                    <td>
                        <asp:Label ID="addressLabel" runat="server" Text='<%# Eval("address"%>' />
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <EditItemTemplate>
                <tr style="background-color#999999;">
                    <td>
                        <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
                    </td>
                    <td>
                        <asp:Label ID="IdLabel1" runat="server" 
Text='<%# Eval("Id"%>' />
                    </td>
                    <td>
                        <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name"%>' />
                    </td>
                    <td>
                        <asp:TextBox ID="ageTextBox" runat="server" Text='<%# Bind("age"%>' />
                    </td>
                    <td>
                       <asp:TextBox ID="mobileTextBox" runat="server" 
Text='<%# Bind("mobile"%>' />
                    </td>
                    <td>
                       <asp:TextBox ID="addressTextBox" runat="server"
 Text='<%# Bind("address"%>' />
                    </td>
                </tr>
            </EditItemTemplate>
            <EmptyDataTemplate>
                <table id="Table1" runat="server" style="background-color#FFFFFF;border-collapsecollapse;border-color#999999;border-style:none;border-width:1px;">
                    <tr>
                        <td>No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <InsertItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
                    </td>
                    <td>&nbsp;</td>
                    <td>
                        <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name"%>' />
                    </td>
                    <td>
                        <asp:TextBox ID="ageTextBox" runat="server" Text='<%# Bind("age"%>' />
                    </td>
                    <td>
                       <asp:TextBox ID="mobileTextBox" runat="server" 
Text='<%# Bind("mobile"%>' />
                    </td>
                    <td>
                     <asp:TextBox ID="addressTextBox" runat="server"
 Text='<%# Bind("address"%>' />
                    </td>
                </tr>
            </InsertItemTemplate>
            <ItemTemplate>
                <tr style="background-color#E0FFFF;color#333333;">
                    <td>
                        <asp:Label ID="IdLabel" runat="server" 
Text='<%# Eval("Id"%>' />
                    </td>
                    <td>
                        <asp:Label ID="nameLabel" runat="server" 
Text='<%# Eval("name"%>' />
                    </td>
                    <td>
                        <asp:Label ID="ageLabel" runat="server" 
Text='<%# Eval("age"%>' />
                    </td>
                    <td>
                        <asp:Label ID="mobileLabel" runat="server"
 Text='<%# Eval("mobile"%>' />
                    </td>
                    <td>
                        <asp:Label ID="addressLabel" runat="server" Text='<%# Eval("address"%>' />
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <table id="Table2" runat="server">
                    <tr id="Tr1" runat="server">
                        <td id="Td1" runat="server">
                            <table id="itemPlaceholderContainer" runat="server" border="1" style="background-color#FFFFFF;border-collapsecollapse;border-color#999999;border-style:none;border-width:1px;font-familyVerdanaArialHelveticasans-serif;">
                                <tr id="Tr2" runat="server" style="background-color#E0FFFF;color#333333;">
                                   <th id="Th1" runat="server">Id</th>
                                   <th id="Th2" runat="server">name</th>
   <th id="Th3" runat="server">age</th>
    <th id="Th4" runat="server">mobile</th>
                                  <th id="Th5" runat="server">address</th>
                                </tr>
 <tr id="itemPlaceholder" runat="server">
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr id="Tr3" runat="server">
                        <td id="Td2" runat="server" style="text-aligncenter;background-color#5D7B9D;font-familyVerdanaArialHelveticasans-serif;color#FFFFFF"></td>
                    </tr>
                </table>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <tr style="background-color#E2DED6;font-weightbold;color#333333;">
                    <td>
                        <asp:Label ID="IdLabel" runat="server" 
Text='<%# Eval("Id"%>' />
                    </td>
                    <td>
                        <asp:Label ID="nameLabel" runat="server"
 Text='<%# Eval("name"%>' />
                    </td>
                    <td>
                        <asp:Label ID="ageLabel" runat="server"
 Text='<%# Eval("age"%>' />
                    </td>
                    <td>
                        <asp:Label ID="mobileLabel" runat="server"
 Text='<%# Eval("mobile"%>' />
                    </td>
                    <td>
                        <asp:Label ID="addressLabel" runat="server" Text='<%# Eval("address"%>' />
                    </td>
                </tr>
            </SelectedItemTemplate>
        </asp:ListView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dbcon %>" SelectCommand="SELECT * FROM [reg]"></asp:SqlDataSource>
   
    </div>
    </form>
</body>

</html>
  












                                 

0 comments:

Post a Comment