Friday, September 21, 2012

Single Quote (') into the data control bind system <%# %>

Here is Tips to put single quote ( ' ) into the data bind control binding syntax that is <%# ... %>

For Example:

OnClientClick=<%# "xyz('" + Eval("DataColumn").ToString() "'); return false;" %>

Direct put the binder syntax after = of the property you want to bind, don't use single or double quote.  And put any string constant before and after your Eval("").

It is use full when we want to call javascript function on the click event of link,button,image etc controls.

Friday, September 14, 2012

SqlConnection from ObjectContext.Connection

Following is C# code to get the SqlConnection from ObjectContext.Connection.
This is usefully to run dynamically created query using ADO.NET using connection string specified into the EDMX ObjectContext object.

C# Code Example :

using (EntityContext context = new EntityContext())
EntityConnection ec = (EntityConnection)context.Connection;
SqlConnection sc = (SqlConnection)ec.StoreConnection;

SqlDataAdapter da = new SqlDataAdapter(strQuery, sc);
DataSet ds = new DataSet();

return ds.Tables[0];