Jul 25, 2008

Alternating styles in ListView- without AlternatingItemTemplate

From within any template, you have access to the current index of the row within the whole data set, using Container.DataItemIndex, and within the currently displayed items, using Container.DisplayIndex. This gives us an easy way to alternate styles:

<li class="<%# Container.DisplayIndex % 2 == 0 ? "even" : "odd" %>">
<%# Eval("Name") %>

Just define the even and odd classes in your stylesheet and you're pretty much done.

kick it on DotNetKicks.com

Jul 24, 2008

Batch Inserts to SQL Server- Stored procedure method

To do batch Updates to SQL server

  • Create DataTable or DataSet and populate it with required rows
  • Next Create a SqlCommand and SqlDataAdapter using that SqlCommand
  • Remember to set the UpdateRowSource property on the Command the the appropriate value
  • Set the UpdateBatchSize Property on the SqlDataAdapter
  • then call SqlDataAdapter.Update(dt) to push the updates to SQL server
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("asin"));
dt.Columns.Add(new DataColumn("trackasin"));
dt.Columns.Add(new DataColumn("isrc"));
for(int i =0; i < 2000;i++)
DataRow dr = dt.NewRow();
dr["asin"] = asin;
dr["trackasin"] = trackasin;
dr["isrc"] = isrc;
//dr.RowState = DataRowState.Added;
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MySpaceMusic"].ConnectionString))
SqlCommand command = new SqlCommand(INSERT_TRACK, connection);
command.CommandType = CommandType.StoredProcedure;
command.UpdatedRowSource = UpdateRowSource.None;
command.CommandTimeout = commandTimeout;

command.Parameters.Add("@asin", SqlDbType.VarChar, 255, dt.Columns[0].ColumnName);
command.Parameters.Add("@trackAsin", SqlDbType.VarChar, 255, dt.Columns[1].ColumnName);
command.Parameters.Add("@isrc", SqlDbType.VarChar, 600, dt.Columns[2].ColumnName);

SqlDataAdapter adpt = new SqlDataAdapter();

adpt.InsertCommand = command;
adpt.UpdateBatchSize = batchSize;
int recordsInserted = adpt.Update(dt);

kick it on DotNetKicks.com

Jul 3, 2008

क्यूट सोंग .. नानी तेरी मोरनी को मोर ले गए

Naani Teri Morni Ko Mor Le Gaye
Baaki Jo Bacha Tha Kaale Chor Le Gaye

Khaake Peeke Mote Hoke,
Chor Baithe Rail Mein
Choron Vaala Dibba Kat Ke, Pahuncha Seedhe Jail Mein

Naani Teri Morni Ko...

Un Choron Ki Khoob Khabar Li,
Mote Thaanedaar Ne
Moron Ko Bhi Khoob Nachaaya,
Jungal Ki Sarkaar Ne

Naani Teri Morni Ko...
Achhi Naani Pyaari Naani,
Roosa-Roosi Chhod De Jaldi Se Ek Paisa De De,
Tu Kanjoosi chod de...

Nani teri morni ko chor le gaye
baaki jo bacha tha kaale chor le gaye

kick it on DotNetKicks.com