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

Peter Bromberg's .NET Blog All Things Programming

Convert DataTable to List<T>

15. March 2016 13:39 by admin in

 DataTable dt = ds.Tables[0];

             var   sponsorids  = dt.Rows.OfType<DataRow>().Select(dr => (int) dr["AccountID"]).ToList();

                return sponsorids;

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>

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.