Monday, May 4, 2009

Showing Gridview Column SUM in FOOTER

Hi All,
This post demonstrates how we can show the SUM of a Particular Column of Gridview in it's FOOTER.

1)Populate Gridview with SQLDATASOURCE.
2).Make Show Footer Property of the Gridview =TRUE
3)On GridView1_RowDataBound event write the below Code:

if (e.Row.RowType == DataControlRowType.DataRow)
sum = sum + Convert.ToInt32(e.Row.Cells[0].Text);
else if (e.Row.RowType == DataControlRowType.Footer)
e.Row.Cells[0].Text = sum.ToString();

Here e.Row.Cells[0].text is shown because I have taken First column as to SUM UP in the Footer :)

And here is the Result...


That's it...and its done.... :)

Thanks,
Nitin Sharma

Tuesday, April 28, 2009

Storing Values into Registry in SET UP Project in WINDOWS

Hi All,

This post discusses about entering values into the Registry while you are making Set Up Project for Windows Applications.

Go to File New Project->Other Project Types->SetUpProject.

After the Solution is added ,right click on the Solution and go to View User Interface.
After then Right click on START -> Add Dialog->Select TextBox(A).

There are Four text Boxes by Default,you can make them invisible false.
Lets take for Textbox1 which is named as EDIT1A.Enter BodyText,Banner Text and Edit1Label Text as desired.
now right click again on Solution->view Registry->HKEY_CURRENT_USER->Software
Add key Named as anyone say Alerts.

Right click on Alerts->New String Value as EMAIL

Now right click on EMAIL-> Set the Value of EMAIL as [EDIT1A]. The point to be noted here is the Value [EDIT1A]. The value has to be kept in Square Brackets.


After running the set up, the registry value will be entered in System Registry under HKEY_CURRENT_USER->Software->Alerts.

Thanks,
Nitin Sharma

Monday, April 20, 2009

Querying Web.SiteMap using LINQ

Querying Web.SiteMap using LINQ

The sample web.sitemap used in this article is shown below:

xml version="1.0" encoding="utf-8"?>

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">

<siteMapNode title="My Favorites">

<siteMapNode title="Favorite Sites">

<siteMapNode title="ASP.NET Home" url="http://www.asp.net" />

<siteMapNode title="ASP.NET Articles" url="http://www.dotnetcurry.com"/>

<siteMapNode title="Windows Client" url="http://www.windowsclient.net" />

<siteMapNode title="Silverlight" url="http://silverlight.net" />

siteMapNode>

<siteMapNode title="Favorite Blogs">

<siteMapNode title="ScottGu Blog" url="http://weblogs.asp.net/scottgu"/>

<siteMapNode title="Technology Blog" url="http://www.devcurry.com" />

<siteMapNode title="SQL Blog" url="http://www.sqlservercurry.com" />

<siteMapNode title="Food Lovers" url="http://foodatarian.com" />

siteMapNode>

<siteMapNode title="Favorite Social Sites">

<siteMapNode title="Twitter" url="http://twitter.com/"/>

<siteMapNode title="FaceBook" url="http://www.facebook.com" />

<siteMapNode title="LinkedIn" url="http://www.linkedin.com" />

<siteMapNode title="Orkut" url="http://www.orkut.com" />

siteMapNode>

siteMapNode>

siteMap>

The Data Source for above web.sitemap is Bulleted List.

<asp:BulletedList ID="linkList" DisplayMode="HyperLink" runat="server">

asp:BulletedList>

List all Url’s in the SiteMap using LINQ

XElement xelement = XElement.Load(Server.MapPath("~/web.sitemap"));

var urlList = xelement.Descendants().Attributes()

.Where(x => x.Name == "url")

.Select(x => x.Value);

foreach (string s in urlList)

{

linkList.Items.Add(s);

}

List Url’s and Title in the SiteMap using LINQ

XElement xelement1 = XElement.Load(Server.MapPath("~/web.sitemap"));

var urlDescList = xelement1.Descendants()

.Where(element => element.LastAttribute.Name.LocalName.Contains("url"))

.Select(nd => new

{

title = nd.Attribute("title")

.Value,

url = nd.Attribute("url")

.Value

});

foreach (var v in urlDescList)

{

ListItem li = new ListItem(v.title, v.url);

linkList.Items.Add(li);

}

List Url’s and Title of a particular node of the SiteMap using LINQ

XElement xelement2 = XElement.Load(Server.MapPath("~/web.sitemap"));

var urlDescList1 = xelement2.Descendants()

// Select node with 'Favorite Social Sites'

.Where(sel => (string)sel.Attribute("title") == "Favorite Social Sites")

.SelectMany(sel => sel.Elements())

.Select(nd => new

{

title = nd.Attribute("title").Value,

url = nd.Attribute("url").Value

});

foreach (var s in urlDescList1)

{

ListItem li = new ListItem(s.title, s.url);

linkList.Items.Add(li);

}

Count the number of nodes in each parent element of SiteMap using LINQ

XElement xelement3 = XElement.Load(Server.MapPath("~/web.sitemap"));

var t = xelement3.Descendants()

.Where(x => x.LastAttribute.Name.LocalName != "url")

.Select(ele => new

{

Name = (string)ele.Attribute("title"),

Count = ele.Elements().Count()

});

Source: http://www.dotnetcurry.com/ShowArticle.aspx?ID=284&AspxAutoDetectCookieSupport=1

Thanks,

Nitin Sharma