Bharath Radhekrishna’s Weblog

May 9, 2008

Displaying total in Footer of Gridview

Filed under: ASP.NET — Tags: — onetidbit @ 8:47 am

If you want to display the Total in the footer of a gridview. Follow the steps:

1) Create a table of employees with salary.

2) Select ename,esalary from emptbl

ename esalary

Bharath 18000

krishna 20000

3) Now in gridview the total of salary must come in footer.

4) .aspx code

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False” BackColor=”#DEBA84″
BorderColor=”#DEBA84″ BorderStyle=”None” BorderWidth=”1px” CellPadding=”3″ CellSpacing=”2″
DataSourceID=”SqlDataSource1″ OnRowDataBound=”GridView1_RowDataBound” ShowFooter=”true”>
<FooterStyle BackColor=”#F7DFB5″ ForeColor=”#8C4510″ />
<Columns>
<asp:BoundField DataField=”ename” HeaderText=”ename” SortExpression=”ename” />
<asp:TemplateField HeaderText=”esalary” SortExpression=”esalary”>

<ItemTemplate>
<asp:Label ID=”Label1″ runat=”server” Text=’<%# Bind(”esalary”) %>’></asp:Label>
</ItemTemplate>
<FooterTemplate>

<asp:Label ID=”Label2″ runat=”server” ></asp:Label>

</FooterTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor=”#FFF7E7″ ForeColor=”#8C4510″ />
<SelectedRowStyle BackColor=”#738A9C” Font-Bold=”True” ForeColor=”White” />
<PagerStyle ForeColor=”#8C4510″ HorizontalAlign=”Center” />
<HeaderStyle BackColor=”#A55129″ Font-Bold=”True” ForeColor=”White” />
</asp:GridView>

</div>
<asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:TestConnectionString %>”
SelectCommand=”SELECT [ename], [esalary] FROM [emptbl]“></asp:SqlDataSource>
</form>
</body>
</html>


5) Code behind:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{

private int Total = 0;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

//DataBinder.Eval method Evaluates data-binding expressions at run time.

int Tot=(int)DataBinder.Eval(e.Row.DataItem,”esalary”);
Total = Total + Tot;
}

if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbltotal = e.Row.FindControl(”Label2″) as Label;
lbltotal.Text = Total.ToString();
}
}
}

Any doubts mail me.

April 10, 2008

Code Snippets in visual studio 2005 - ASP.NET

Filed under: ASP.NET, Information technology — Tags: — onetidbit @ 11:43 am

Hello friends I want to share something on “Code Snippets” with you.

Code Snippet

Q: What is a “Code Snippet”?

A: A Code Snippet is a reusable block of code. Unlike a static copy-and-paste approach, code snippets allow for dynamic instances of code

by allowing placeholders into mini templates of code. Code snippets are a new feature of Visual Studio 2005.

Q: How do I use a Code Snippet?

A: In the Visual Studio 2005 code editor, you can invoke snippets with [ctrl][k][x] keyboard shortcut. IntelliSense will then display a

context menu displaying the available code snippets to choose. However, most code snippets are available without using the keyboard

shorcut. If you know the shortcut name of the code snippet, simply type the name and press tab to invoke.

Now we will see how we can use snippets here.
I will write a small snippet for disconneceted data access with dataset.

1) Open nottepad.
2) Type the code in it and save it as sample.snippet.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns=”http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet”>
<CodeSnippet Format=”1.0.0″>
<Header>
<Title>Disconnected Data architecture</Title>
<Shortcut>Dataset</Shortcut>
<Description>Code snippet for Disconnected data access</Description>
<Author>Bharath Radhekrishna</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language=”csharp”><![CDATA[dataset
SqlConnection cn = new SqlConnection();
string selquery = $selquery$;
SqlDataAdapter da = new SqlDataAdapter(selquery, cn);
DataSet ds = new DataSet();
da.Fill(ds);
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>


3) After saving this. Go to visual studio 2005. Click Tools > CodeSnippets manager or ctrl+K, ctrl+B.
and add this snippet to library.

4) While you are coding right click the mouse. You will see an option of “insert snippet”. when you click it will tell us
to insert the snippet we like. For example if take the above snippet it will be displayed with the name as:
“Disconnected Data architecture”.If we click it will display the code as:

SqlConnection cn = new SqlConnection();
string selquery = ;
SqlDataAdapter da = new SqlDataAdapter(selquery, cn);
DataSet ds = new DataSet();
da.Fill(ds);

So everytime it is not necessary for us to write whole sentence or connections.It will reduce our burden of writing commonly used
code everytime.

For more info on Code snippets you can refer to:

http://gotcodesnippets.com/faq.aspx
http://www.google.com/search?q=how+to+insert+a+code+snippet+in+visual+web+developer+2005&sourceid=navclient-ff&ie=UTF-8&rlz=
1B3GGGL_enIN246IN246.

Screens

Codesnippet while right clicking mouse

March 31, 2008

Retrieving port number with sql query

Filed under: Sql server — onetidbit @ 12:47 pm


Declare @PortNumber VarChar(7)

Exec Xp_RegRead

@RootKey=’HKEY_LOCAL_MACHINE’,

@Key=’Software\Microsoft\Microsoft Sql Server\SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp’,

@Value_Name=’TcpPort’,

@Value=@PortNumber OutPut

Print ‘Port Number:’

Print @PortNumber

When you execute this you will get a problem to enable XP_CMDshell.You can enable by this.Read the article at:
Enabling xp_cmdshell in SQL Server 2005

Retrieving IP address of a system with SQL Query

Filed under: 1 — onetidbit @ 12:39 pm

Retrieving IP address of a system with SQL Query

CREATE PROCEDURE getIPAdress

(

@Hostname VARCHAR(255)

)

AS

SET NOCOUNT ON

CREATE TABLE #Results

(

Results VARCHAR(4000)

)

DECLARE @Commandstring VARCHAR(300)

SET @Commandstring = ‘ping ‘ + @Hostname

INSERT INTO #Results

EXEC master..xp_cmdshell @Commandstring

Select DISTINCT SUBSTRING(Results,12,CHARINDEX(’:',Results)-12) AS HostIpAdress from #Results

Where Results LIKE ‘Reply From%’

DROP TABLE #Results

GO
============================
To know result

exec getIPAdress ‘ABCXP10′

ABCXP10 is a system name

Blogged with Flock

Tags:

March 29, 2008

javascript with response.redirect

Filed under: ASP.NET — onetidbit @ 6:18 am

Q) I had been trying to use javacript to alert some message and after that I do a response.redirect to another page.

But the alert message seems not appearing and it just redirect to another page.

A) use the below code.here we use location.replace

Location.replace

Syntax:
location.replace(URL)

The replace method replaces the current History entry with the specified URL. After calling the replace method, you cannot navigate back to the previous URL using the browser’s Back button.

Usage

string s = “alert(’Your Profile Is Successfully Updated’);location.replace(’Client_home.aspx’);”;
Page.ClientScript.RegisterStartupScript(this.GetType(), “sri”, s, true);

Blogged with Flock

March 27, 2008

Windows officelive website doesnt support safari web browser

Filed under: 1 — onetidbit @ 8:07 am

When I am trying to open office live it is taking url as:
http://home.officelive.com/Misc/CompatibleShell.aspx?linkId=UnsupportedBrowser

It means office live not supporting safari web browser
https://home.officelive.com

View the screen shot at:
http://www.flickr.com/photos/89692283@N00/2365278477/

Blogged with Flock

March 25, 2008

Links for Content Management system in ASP.NET

Filed under: ASP.NET — onetidbit @ 5:31 am

Open source

http://www.dotnetnuke.com/
http://www.rainbowportal.net/
http://drupal.org/


http://aspalliance.com/simplecms/default.aspxhttp://www.codeplex.com/SampleCMS

http://www.codeplex.com/umbraco/Release/ProjectReleases.aspx?ReleaseId=6344

http://www.davidpirek.com/CMS/


http://graffiticms.com/
http://www.kentico.com/
http://www.axcms.net/en_axcms_home.AxCMS?ActiveID=1848

Blogged with Flock

Tags:

March 10, 2008

validate textbox with only numbers using Javascript code

Filed under: ASP.NET — onetidbit @ 7:53 am

We can validate textbox with only numbers by writing this Javascript code and calling at onkeypress event of text box

<!–
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
      //–>

   <asp:TextBox ID=”txt_maxage” Onkeypress=”return isNumberKey(event)” runat=”server”></asp:TextBox>

Blogged with Flock

Tags:

Play music when mouse hovers on a link in ASP.NET

Filed under: ASP.NET — onetidbit @ 7:24 am

Javascript code
============

Write this in .aspx page.

<script language=”JavaScript”><!–
// Sound on Mouseover javascript supplied by http://www.hypergurl.com

var aySound = new Array();
// PLACE YOUR SOUND FILES BELOW
aySound[0] = “sound002.wav”;
aySound[1] = “sound003.wav”;
aySound[2] = “sound004.wav”;
aySound[3] = “sound005.wav”;
aySound[4] = “sound006.wav”;
aySound[5] = “sound007.wav”;
aySound[6] = “sound008.wav”;
aySound[7] = “sound009.wav”;
aySound[8] = “sound010.wav”;
// Don’t alter anything below this line

IE = (navigator.appVersion.indexOf(”MSIE”)!=-1 && document.all)? 1:0;
NS = (navigator.appName==”Netscape” && navigator.plugins["LiveAudio"])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = “<DIV ID=’auEmb’ STYLE=’position:absolute;’></DIV>”;
document.body.insertAdjacentHTML(”BeforeEnd”,Str);
}
var Str = ”;
for (i=0;i<aySound.length;i++)
Str += “<EMBED SRC=’”+aySound[i]+”‘ AUTOSTART=’FALSE’  LOOP=’TRUE’ HIDDEN=’TRUE’>”
if (IE) auEmb.innerHTML = Str;
else {
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.soundfiles:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play) {
if (IE) this.src = play? aySound[whSound]:”;
else eval(”this.document.embeds[whSound].” + (play? “play()”:”stop()”))
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }
//–></script>
<!– –>


=============
Code in ASP.NET
=============

<td width=”51%” valign=”top”  class=”nav”><div><a href=”#” class=”htext2″ onmouseover=”playSound(0)” onmouseout=”stopSound(0)”>&ndash; Command Altitude<br />
          </a>
              <br />
          <a href=”#” class=”htext2″ onmouseover=”playSound(2)” onmouseout=”stopSound(2)”>&ndash;Command Heading</a><br />
              <br />
          </div>
            <div><a href=”#” class=”htext2″ onmouseover=”playSound(3)” onmouseout=”stopSound(3)”>&ndash;Command Speed</a>
                <br />
              <br />
              <a href=”#” class=”htext2″ onmouseover=”playSound(4)” onmouseout=”stopSound(4)”>&ndash;Override</a> </div>
          </td>
          <td width=”51%” valign=”top”  class=”nav”><div><a href=”#” class=”htext2″ onmouseover=”playSound(5)” onmouseout=”stopSound(5)”>&ndash;Permanent   Override<br />
          </a>
              <br />
          </div>
              <div><a href=”#” class=”htext2″ onmouseover=”playSound(6)” onmouseout=”stopSound(6)”>&ndash;Temporary Override</a><br />
                  <br />
              </div>
            <div class=”htext2″>&ndash;<a href=”#” class=”htext2″ onmouseover=”playSound(7)” onmouseout=”stopSound(7)”>Cruise</a><br />
            </div>
            <div>
                <br />
                <a href=”#” class=”htext2″ onmouseover=”playSound(8)” onmouseout=”stopSound(8)”>&ndash;Manual Heading</a></div></td>
        </tr>
      </table>
    </td>

Any doubts mail me:  radhek@gmail.com

Blogged with Flock

Tags: ,

March 6, 2008

Full screen with javascript in ASP.NET

Filed under: ASP.NET — onetidbit @ 4:53 am

 
Here I am givinng javascript code by using which we can make full screen or normal mode.
This code wcan be useful in ASP.NET

<SCRIPT LANGUAGE=”JavaScript”>

function fullScreen(theURL)
{
window.opener=null;
this.close();
window.open(theURL, ”, ‘fullscreen=yes, scrollbars=auto’);

}
function fuScreen(theURL)
 {
 window.opener=null;
 this.close();
window.open(theURL, ”, ‘fullscreen=no, toolbar=yes ,menubar=yes ,status=yes ,scrollbars=yes, location=yes, resizable=yes, maximized=0, height=800, width=1280, left=0,top=0′);
}
function window_onload()
{
window.moveTo(0,0);
top.window.resizeTo(screen.availWidth,screen.availHeight);

}

//  End –>
</script>

Using this in ASP.NET
=================

<td width=300 align=”right” valign=”middle”>
                <a href=”javascript:fullScreen(’Override_attack_Tut3.aspx’);”><img src=”images/fullscreen mode.jpg” border=”0″ /></a><td>
            <td width=300 align=”center” valign=”middle”>
                <a href=”javascript:fuScreen(’Override_attack_Tut3.aspx’);”><img src=”images/normal mode.jpg”border=”0″ /></a><td>

Blogged with Flock

Tags:

Older Posts »

Blog at WordPress.com.