Google+ Peter Bromberg's .NET Blog | All Things Programming

Peter Bromberg's .NET Blog All Things Programming

Customize Url Parameters in Telerik RadGrid Hyperlink Column

28. August 2015 12:36 by admin in
<telerik:RadGrid ID="grdBlah" runat="server" AllowMultiRowSelection="false" AllowPaging="true"AutoGenerateColumns="False" CellPadding="0" GridLines="Both" PageSize="15" ShowFooter="false"OnPageIndexChanged="grdBlah_OnPageIndexChanged"AllowSorting="true"OnSortCommand="grdBlah_OnSortCommand"OnNeedDataSource="grdBlah_NeedDataSource"OnItemDataBound="grdBlah_OnItemDataBound"><MasterTableView ShowFooter="false"><Columns><telerik:GridTemplateColumn UniqueName="btnViewTransactionDetails"ItemStyle-Width="100" HeaderStyle-Width="100"HeaderText="Action"ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"><ItemTemplate><asp:HyperLink ID="HyperLink1" runat="server" Text="View Detail"NavigateUrl='<%#String.Format("~/Pages/TransactionDetails.aspx?ID={0}&accountID={1}", DataBinder.Eval(Container.DataItem,"transID")  , hfAccountID.Value) %>'></asp:HyperLink></ItemTemplate></telerik:GridTemplateColumn></Columns></MasterTableView><ClientSettings EnablePostBackOnRowClick="true"><Selecting AllowRowSelect="true" /></ClientSettings>
</telerik:RadGrid>

This example should be self-explanatory. If there are more parameters, handle them exactly as in the example code below.

 

How to get the Url to the current page in ASP.NET

24. August 2015 06:13 by admin in

There are lots of methods but I think this one is the easiest:

 

 string returnUrl = Request.Url.GetLeftPart(UriPartial.Authority);

Using ternary operators in inline Lambda LINQ queries

11. June 2015 06:41 by admin in

Let's say you have an Entity Framework query that returns a list of type User. And let's say your search query has multiple potential search filters that you want to apply.

Here's an example of where the "fullLoginName" field could be a full name that you can split on, such as "Clyde Thomes", or it could be a single items such as "Administrator":

if (isFilteredByLastName){	targetUsers = targetUsers.Where(x=>x.fullLoginName.Contains(" ")?x.fullLoginName.Split(' ')[1]==lastName:x.fullLoginName.Contains(lastName)).ToList();}

You can then use the targetUsers result as the subject of the next filter item.

How to Execute Generic Type SQL with Entity Framework

2. June 2014 11:28 by admin in ENTITY FRAMEWORK

public static T ExecuteSql<T>(DbContext ctx, string sql, List<DbParameter> parms)

{

DbCommand cmd = ctx.Database.Connection.CreateCommand();

cmd.CommandText = sql; cmd.CommandType = CommandType.Text;

foreach (DbParameter p in parms) cmd.Parameters.Add(p);

try {

ctx.Database.Connection.Open();

DbDataReader reader = cmd.ExecuteReader();

ObjectResult<T> jInfo = ((IObjectContextAdapter) ctx) .ObjectContext .Translate<T>(reader);

return jInfo.FirstOrDefault();

}

finally { ctx.Database.Connection.Close();

}

}