Showing posts with label Data List And Repeater. Show all posts
Showing posts with label Data List And Repeater. Show all posts

Thursday, July 3, 2014

Data List And Repeater

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Repeater ID="rpt" runat="server">
      <ItemTemplate>
<table>
            <tr>
              <td>
<asp:Label ID="lblfirstname" runat="server" Text='<%#Bind("Firstname") %>' Font-Bold="true"></asp:Label>
<asp:Label ID="lblLastname" runat="server" Text='<%#Bind("LastName") %>' Font-Bold="true"></asp:Label>
            
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="lbldesignation" runat="server" Text='<%#Bind("designation") %>' Font-Bold="true"></asp:Label>

              </td>
            
            </tr>
            <tr>
              <td>
                <asp:Label ID="lblsalary" runat="server" Text='<%#Bind("Salary") %>' Font-Bold="true"></asp:Label>

              </td>
            </tr>
          </table>
      </ItemTemplate>
    </asp:Repeater>
      <asp:DataList ID="dtl" runat="server" RepeatColumns="1" BorderColor="Gray" BorderStyle="Solid">
        <ItemTemplate>
          <table>
            <tr>
              <td>
<asp:Label ID="lblfirstname" runat="server" Text='<%#Bind("Firstname") %>' Font-Bold="true"></asp:Label>
<asp:Label ID="lblLastname" runat="server" Text='<%#Bind("LastName") %>' Font-Bold="true"></asp:Label>
            
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="lbldesignation" runat="server" Text='<%#Bind("designation") %>' Font-Bold="true"></asp:Label>

              </td>
            
            </tr>
            <tr>
              <td>
                <asp:Label ID="lblsalary" runat="server" Text='<%#Bind("Salary") %>' Font-Bold="true"></asp:Label>

              </td>
            </tr>
            <tr>
             <td>
               <asp:Button ID="btnsubmit" runat="server" Text="Submit" CommandArgument=<%#Bind("Salary") %> OnCommand="submit_commend" />
             </td>
            </tr>
          </table>
        </ItemTemplate>
      </asp:DataList>
    </div>
    </form>
</body>
</html>


-----------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Firstname", typeof(string));
        dt.Columns.Add("LastName", typeof(string));
        dt.Columns.Add("designation", typeof(string));
        dt.Columns.Add("Salary", typeof(string));
        dt.Rows.Add("Trinadh", "K", "Sr.developer", "100000");
        dt.Rows.Add("srinivas", "M", "Sr.developer", "1000000");
        dt.Rows.Add("Siva", "Master", "Sr.developer", "500000");
        dt.Rows.Add("Mahesh", "Agadu", "Sr.developer", "700000");
        dt.Rows.Add("Vishnu", "Agutadu", "Sr.developer", "800000");
        dt.Rows.Add("Rakesh", "Danush", "Sr.developer", "900000");

        dtl.DataSource = dt;
        dtl.DataBind();

        rpt.DataSource = dt;
        rpt.DataBind();



    }
    public void submit_commend(object sender, CommandEventArgs e)
  
    {
        string id = e.CommandArgument.ToString();
    }
}