Monday, January 18, 2010

How to read Repeater control's row in ASP.NET?

How to read entire row in a repeater control when i click its respective Link or ButtonHow to read Repeater control's row in ASP.NET?
even though I have no idea what your talking about I agree 100% with smutty because his my long lost brother.:)


....... I MISS YOU BROHow to read Repeater control's row in ASP.NET?
Your question is a bit vague. To edit Items, I suggest you resort to a DataList. It offers EditTemplates which make your life easier. Anyways, here's a simple example on a repeater. The Details link makes use of the row info and sends the user to Customer Details page with appropriate QueryString.





%26lt;%@ Page Language =';C#'; %%26gt;





%26lt;%@ Import Namespace =';System.Data'; %%26gt;


%26lt;%@ Import Namespace =';System.Data.SqlClient'; %%26gt;





%26lt;script runat =';server';%26gt;


protected void Page_Load (object sender, EventArgs e)


{


if ( !Page.IsPostBack )


{


BindRepeater();


}


}





private void BindRepeater()


{


SqlConnection MyConnection;


SqlCommand MyCommand;





MyConnection = new SqlConnection(';server=. ; DataBase=Northwind; uid=sa;pwd=;';);


MyCommand = new SqlCommand( ';SELECT TOP 10 * FROM CUSTOMERS ';, MyConnection );





DataTable dt = new DataTable();


SqlDataAdapter da = new SqlDataAdapter( MyCommand );


MyCommand. Connection.Open();


da.Fill(dt);


MyCommand .Dispose();


MyConnection .Dispose();





repeater. DataSource = dt;


repeater.DataBind();





}


%26lt;/script%26gt;





%26lt;html xmlns=';http://www.w3.org/1999/xhtml';%26gt;


%26lt;head runat=';server';%26gt;


%26lt;title%26gt;Untitled Page%26lt;/title%26gt;


%26lt;/head%26gt;


%26lt;body%26gt;


%26lt;form id=';form1'; runat=';server';%26gt;


%26lt;table border=';0'; cellpadding =';0'; cellspacing =';0';%26gt;


%26lt;asp:Repeater ID=';repeater'; runat =';server'; %26gt;


%26lt;ItemTemplate%26gt;


%26lt;tr%26gt;


%26lt;td%26gt;


Customer Id:%26lt;/td%26gt;


%26lt;td%26gt;


%26lt;%# Eval( ';CustomerID'; ) %%26gt;


%26lt;/td%26gt;


%26lt;td style=';width: 50px;';%26gt;


%26lt;/td%26gt;


%26lt;td%26gt;


Customer Name:


%26lt;/td%26gt;


%26lt;td%26gt;


%26lt;%# Eval('; ContactName ';)%%26gt;


%26lt;/td%26gt;


%26lt;td%26gt;


%26lt;a href='CustomerDetails.aspx? CustomerId= %26lt;%# Eval( ';CustomerID';) %%26gt;' id =';lnkCustomerDetails'; %26gt;Details%26lt;/a%26gt;


%26lt;/td%26gt;


%26lt;/tr%26gt;


%26lt;/ItemTemplate%26gt;


%26lt;SeparatorTemplate%26gt;


%26lt;tr%26gt;


%26lt;td colspan=';6';%26gt;


%26lt;hr /%26gt;


%26lt;/td%26gt;


%26lt;/tr%26gt;


%26lt;/SeparatorTemplate%26gt;


%26lt;/asp:Repeater%26gt;


%26lt;/table%26gt;


%26lt;/form%26gt;


%26lt;/body%26gt;


%26lt;/html%26gt;

No comments:

Post a Comment