<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!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 runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Repeater ID="rptrTable" runat="server" onitemcommand="rptrTable_ItemCommand" > <HeaderTemplate> <table border=3> <tr> <th>Agent ID</th> <th>First Name</th> <th>Last Name</th> <th>City</th> <th>SSN</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%# DataBinder.Eval(Container.DataItem,"AgentID") %> </td> <td> <%# DataBinder.Eval(Container.DataItem,"FirstName") %> </td> <td> <%# DataBinder.Eval(Container.DataItem,"LastName") %> </td> <td> <%# DataBinder.Eval(Container.DataItem,"City") %> </td> <td> <%# DataBinder.Eval(Container.DataItem,"SSN") %> </td> <td> <asp:Button ID="btnShow" runat="server" Text="Show" CommandName="ShowButt" CommandArgument='<%# Eval("AgentID") %>' /> </td> <td> <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="EditButt" /> </td> </tr> </ItemTemplate> </asp:Repeater> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { SqlConnection connection; SqlCommand command; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string strcon = ConfigurationManager.ConnectionStrings["AgentConn"].ConnectionString; connection = new SqlConnection(strcon); command = new SqlCommand("prcAgentShow", connection); command.CommandType = CommandType.StoredProcedure; connection.Open(); DataTable dt = new DataTable(); SqlDataReader dataReader = command.ExecuteReader(); dt.Load(dataReader); rptrTable.DataSource = dt; rptrTable.DataBind(); } } protected void rptrTable_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName.Equals("ShowButt")) { Label1.Text = "u clik the show button "; } } }
protected void rptrTable_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "ShowButt") { Label1.Text = e.CommandArgument.ToString(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)