adsense

Wednesday, October 26, 2011

get the current row in GridView Row Command

This not directly possible in ASP.NET.  Following article discusses a workaround to get the current row in GridView RowCommand event.

http://ranafaisal.wordpress.com/2008/03/31/how-to-get-the-current-row-in-gridview-row-command-event/ 

The inline code for gridview displayed below.

<asp:GridView ID="grdTrackedItems" runat="server" AutoGenerateColumns="False" Width="330px"
            BorderStyle="None" OnRowEditing="EditRecord" OnRowCommand="RowCommand">
            <Columns>
              <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                  <asp:Label ID="lblItem" runat="server" Text='<%# Eval("Item") %>' />
                </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField>
                <ItemTemplate>
                  <asp:ImageButton ID="imgDelete" runat="server" ImageUrl="~/Resources/Images/Delete.png"
                    Height="12" Width="12" ToolTip="Delete" CommandName="Delete" />
                </ItemTemplate>
                <ItemStyle Width="22px" />
              </asp:TemplateField>
              <asp:TemplateField>
                <ItemTemplate>
                  <asp:ImageButton ID="imgEdit" runat="server" ImageUrl="~/Resources/Images/Edit.png"
                    Height="12" Width="12" ToolTip="Edit" />
                </ItemTemplate>
                <ItemStyle Width="22px" />
              </asp:TemplateField>
            </Columns>
          </asp:GridView>


Make sure you are handling the OnRowEditing event(keep it blank)
protected void EditRecord(object sender, GridViewEditEventArgs e)
{
    
}

 
Cheers,
Happing coding
Samtha

Friday, October 21, 2011

Linq Select Top X

use flowing linq query to ger top x (x is no of rows required) for the result


var result= (from t in tblItems.AsEnumerable()
                   select t).Take(x);

cheers
Samitha


Monday, October 17, 2011

Upgrading an ASP.NET 3.5 Web site that has a 3.5 Chart control to ASP.NET 4 requires changes to web.config and register directive

If you have used Microsoft Chart control in your VS 2008 project and upgraded to VS 2010 following steps should be followed to upgrade to Chart control 4.0 (Extracted from Visual Studio 2010 Read me).


Updgrading an ASP.NET 3.5 Web site that has a 3.5 Chart control to ASP.NET 4 will cause the following error on build:
Error 1 The type 'System.Web.UI.DataVisualization.Charting.Chart' exists in both 'c:\Windows\assembly\GAC_MSIL\System.Web.DataVisualization\3.5.0.0__31bf3856ad364e35\System.Web.DataVisualization.dll' and 'c:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.DataVisualization.dll' C:\Websites\Vs2008Sp1_Website_35_Cs_WithChart\Default.aspx 15
To resolve this issue:
References that still point to the 3.5 Chart control in web.config after upgrade must be updated to reference version 4.
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">lt;controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
......
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="ChartImageHandler"/>
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>
......
Register directive in the Web forms page must be removed or updated to reference version 4.
<%@ Register assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>
The existing System.Web.DataVisualization assembly in the bin folder may have to be deleted because this assembly is part of the .NET Framework 4.


Friday, October 7, 2011

copy Microsoft.ReportViewer.ProcessingObjectModel.dll

When you are trying to build a project with Microsoft Reports you may not be able to build it successfully. You'll be needed to copy the Microsoft.ReportViewer.ProcessingObjectModel.dll to your bin directory of the web project. Following article gives the detailed steps do it.

http://am22tech.com/s/22/FORUM1/default.aspx?g=posts&m=804

cheers
samitha





Ms Chart assembly loading problem

Following error will be given when you trying to open the page first time with chart control in the designer. (newly formatted machines).

.
FileLoadException: Could not load file or assembly 'System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]

Following thread discusses the method to fix above issue.

http://social.msdn.microsoft.com/Forums/en/MSWinWebChart/thread/d976b659-264a-4731-935c-08c02865002f

The solution proposed by msdn needs improved solved my problem.


Cheers
samitha