Friday, 14 February 2014

Gridview with Fixed Header using CSS



http://csharpdotnetfreak.blogspot.com/2009/07/scrollable-gridview-fixed-headers-asp.html

We need to alter the header's width as per we need using HeaderStyle-Width property
 
HTML Source
 
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" Height="200px" 
                       Width="200px" ScrollBars="Vertical">

<asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" DataKeyNames="ID"
              DataSourceID="SqlDataSource1"
              RowStyle-VerticalAlign="Bottom"
              OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" 
                InsertVisible="False" 
                ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" 
                                 SortExpression="Name" />
<asp:BoundField DataField="Location" HeaderText="Location" 
                             SortExpression="Location" />
</Columns>
<HeaderStyle CssClass="header"Height="20px" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name], [Location] FROM [Details]">
</asp:SqlDataSource>
</asp:Panel>
</div></form>
 
CSS Code 
 <head runat="server">
<title>Creating scrollable GridView with fixed headers</title>
<style type="text/css">
  .header
  {
    font-weight:bold;
    position:absolute;
    background-color:White;
  }
  </style>
</head>
 
Code Behind 
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if(e.Row.RowIndex == 0)
           e.Row.Style.Add("height","40px");
        }
    }

Javascript ToolTip


Consider the following link
http://www.menucool.com/tooltip/javascript-tooltip

Download the demo source code.(It contains tooltip.css file and tooltip.js file)

We need to add that two files in solution and Register that file in load page.
In code behind , while rowdatabound event we need to add the  
if (e.Row.Cells[8].Text.Replace("&nbsp;", "") != "")
  {
       e.Row.Cells[8].Attributes.Add("onmouseover", "tooltip.pop(this,'" + e.Row.Cells[8].Text + "')");
   }
else
  {
       e.Row.Cells[8].Attributes.Remove("onmouseover");
   }
  


it will available in downloaded file.


Tuesday, 11 February 2014

Get SQL data from another server - OPENROWSET

SELECT * into tr
FROM    OPENROWSET( 'SQLOLEDB',
                    'Server=10.10.1.89\SQLEXPRESSR2;UID=sa;PWD=password',                  
                    'SET FMTONLY OFF;SET NOCOUNT ON; exec BASE89.dbo.GetPWD @UID=''21'''
                  )
select * from tr


http://technet.microsoft.com/en-us/library/ms191188%28v=sql.105%29.aspx

Monday, 20 January 2014

Simple trigger in sql server 2008 R2

CREATE TRIGGER trig_Insert_Employee
ON Emp
FOR INSERT
AS
Begin
    Insert into dbo.backtable (id, insertdate)   select MAX(id),GETDATE() from Emp
    
End



here
Emp is table name , whenever emp table gets insert the trigger will get fired! 





























insert into Emp(id,name) values(2,'First')


select * from sys.objects where type='TR'

The above query will display the triggers in database. and it holds parent object id.

varbinary to file sql server 2008 R2


declare @IMG varbinary(max)
declare @FileName varchar(max)
declare @ObjectToken INT

set @IMG=(select Binarydata from File_T where ID=3)
--SET @FileName = 'd:\' + replace(replace(replace(replace(convert(varchar,getdate(),121),'-',''),':',''),'.',''),' ','') + '.pdf'
set @FileName='d:\Image1.pdf'
      
       

        EXEC sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT
        EXEC sp_OASetProperty @ObjectToken, 'Type', 1
        EXEC sp_OAMethod @ObjectToken, 'Open'
        EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @IMG
        EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, @FileName, 2
        EXEC sp_OAMethod @ObjectToken, 'Close'
        EXEC sp_OADestroy @ObjectToken
       
     

enable ole automation sql 2008 r2

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO

Saturday, 11 January 2014

confirm box for LinkButton in asp.net

<asp:LinkButton ID="lnkMaterialIndentRevise" runat="server" Text="Indent Revise"
                                        OnClientClick="javascript:return confirm('Are you sure you want to revise this indent?')" OnClick="lnkMaterialIndentRevise_Click"></asp:LinkButton>