Memos of my LinqDatasource experience

How to group by more than 1 table column (attribute, property)?

GroupBy="new(Roles.RoleName, Roles.RoleId)" Access with: Key.RoleName, (for example in your listview or gridview)

<asp:LinqDataSource runat="server" ID="ldsUsers"
ContextTypeName="MyPrivateProject.Test.DataAccess.MyPersonalPrivateDataContext" TableName="Users" GroupBy="new(Roles.RoleName, Roles.RoleId)" OrderGroupsBy="Key.RoleName" OrderBy="UserName, Lastname, Firstname" Select="new(Key, Count() As RecordCount, It As Users)" > </asp:LinqDataSource>

How to use Guids in LinqDataSource where Parameters?

Use DbType="Guid" instead of Type="xxx". TODO: Check input param! e.g. MyPage.aspx?UserIdInput=xxxasd-grrrr-blabla-TEXT-FFAILS --> throws an error

<asp:LinqDataSource runat="server" ID="ldsUsers"
   ContextTypeName="MyPrivateProject.Test.DataAccess.MyPersonalPrivateDataContext"
   TableName="Users"
   Where="UserId = @UserIdInput" EnableUpdate="True">
     <WhereParameters>
          <asp:QueryStringParameter
                 DefaultValue="none" Name="UserIdInput"
                 QueryStringField="UserId" 
              DbType="Guid"  />
     </WhereParameters>
</asp:LinqDataSource>

Syntax highligthing provided by FaziBear's Google widget But removed cause it doesnt support Highlighting of single lines nor sections

Dynamic Data first steps and first issues :-)

I started working on a project with asp.net Dynamic Data and MVC.

We are using Linq2Sql, and I created 2 nested asp:Listview's to display Master/Detail data, grouped by Master.

 

With the following code

<ItemTemplate> 
      <tr> 
          <td> 
              <asp:DynamicControl ID="DynamicControl1" runat="server" DataField="EquipmentName" Mode="ReadOnly" /> 
          </td> 
          <td> 
              <asp:LinkButton runat="server" ID="ilnkDelete" Text="Remove" CommandName="DeleteEquipment" 
                  CommandArgument='<%# Eval("EquipmentID") %>' OnClientClick='return confirm("Are you sure you want to delete this item?");' /> 
          </td> 
      </tr> 
</ItemTemplate>

 

I get an error if I click on the Delete Link

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The DynamicControl/DynamicField needs to exist inside a data control that is bound to a data source that supports Dynamic Data.

 

After struggling around with 2 LinqDatasources, UpdatePanels, Gridviews and all other possibilities, I found out:
If I change all the DynamicControl to Eval it works!

This code works

<ItemTemplate>     <tr>         <td>            <%# Eval("EquipmentName") %>         </td>         <td>             <asp:LinkButton runat="server" ID="ilnkDelete" Text="Remove" CommandName="DeleteEquipment"                 CommandArgument='<%# Eval("EquipmentID") %>' OnClientClick='return confirm("Are you sure you want to delete this item?");' />         </td>     </tr> </ItemTemplate>

How to set the focus to the username textbox of asp:LoginView?

jQuery is so cool, I had to blog about this!

<script type="text/javascript">
     function pageLoad() {
         $(":text:first").focus()
     } </script>

Also google gave no satisfying solution for this! Google search for Loginview jquery set focus textbox

How to write to the Console window from a Windows Forms application?

 

Check out that post about How to write to the started console window.
http://www.rootsilver.com/2007/08/how-to-create-a-consolewindow

image


Like Jeffrey mentioned in his post, I also DON'T recommend to do that.
A Windows Application should use the Windows as GUI and not the console window...

Every Winform Application MUST have this !

A Splashscreen with current loading Assemblies!!!

Saw this in Citavi - Reference Management and Knowledge Organization 
A Splash form that's shows the loading of the single dlls.

image

 

How to do this?

 

First I saw this Event with Reflector and Intellisense.

 AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(GuiManager.CurrentDomain_AssemblyLoad);

Then I thought that's easy.
But it isn't, cause the main assemblies are already loaded when you put that event registration as first line in your static Main Code.
So they want show up in your output!

 

So the solution is

        [STAThread]
        static void Main()
        {            
            AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;
            
            PrintLoadedAssemblies(AppDomain.CurrentDomain);
            // Lists mscorlib and this assembly
   
            Application.Run(new Form());
        }


        private static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
        {
            Print(args.LoadedAssembly.GetName().Name);
        }

        private static void Print(string name)
        {
            Console.WriteLine(string.Format("Assembly loaded: {0}", name));
            //YourPersonal-SplashScreen.ReportProgress(args.LoadedAssembly.GetName().Name);
        }   

        static void PrintLoadedAssemblies(AppDomain domain)
        {
            foreach (Assembly a in domain.GetAssemblies())
            {
                Print(a.GetName().Name);
            }
        }

 

If you try this in Visual Studio you can see the assemblies listed in the Output Window.
If you try it from the Console you can't see them.

See next post for: How to write to the Console from an Winforms Application

Latest Posts

Popular Posts