Thursday, July 30, 2009

Different ways of reading and writing text file data in .NET

Different ways of reading and writing text file data in .NET

Dynamically Generate Meta Tags for ASP.NET Pages using LINQ To XML

Dynamically Generate Meta Tags for ASP.NET Pages using LINQ To XML

Url Rebasing in ASP.NET 2.0

Url Rebasing in ASP.NET 2.0: ASP Alliance: "Url Rebasing"

Let’s say we have an image control with relative path on the masterpage html, and Masterpage is in one folder and the content page is in different folder. The relative image path given in the masterpage html markup points to the wrong location and the image is not rendered. To avoid these sorts of problems Asp.Net rebases relative urls known as Url Rebasing.

Thursday, July 23, 2009

Rss Feed to Listview with DataPager in Asp.net

Displaying Rss Feed in  Listview also using DataPager in Asp.net sample.
 
 
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="feedtolistview.aspx.cs" Inherits="feedtolistview" %>

<!

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 id="Head1" runat="server">

<title>Using DataPager and ListView Controls with a Custom Data Source</title>

</

head>

<

body>

<form id="form1" runat="server">

<div>

<asp:DataPager ID="dataPager" runat="server" PagedControlID="listItems" QueryStringField="page"

PageSize="5" >

<Fields>

<asp:NextPreviousPagerField FirstPageText="&lt;&lt;" ShowFirstPageButton="True"

ShowNextPageButton="False" ShowPreviousPageButton="False" />

<asp:NumericPagerField />

<asp:NextPreviousPagerField LastPageText="&gt;&gt;" ShowLastPageButton="True"

ShowNextPageButton="False" ShowPreviousPageButton="False" />

</Fields>

</asp:DataPager>

<br />

<asp:ListView ID="listItems" runat="server" DataSourceID="xmlDataSource">

<LayoutTemplate>

<asp:PlaceHolder runat="server" ID="itemPlaceholder" />

</LayoutTemplate>

<ItemTemplate>

<h3><a href="<%# XPath("link") %>"><%# XPath("title") %></h3> </a>

<%

# XPath("description")%>

</ItemTemplate>

<ItemSeparatorTemplate>

<hr />

</ItemSeparatorTemplate>

</asp:ListView>

<asp:XmlDataSource ID="xmlDataSource" runat="server" DataFile="http://rss.news.yahoo.com/rss/topstories"

XPath="rss/channel/item"></asp:XmlDataSource>

<asp:DataPager ID="dataPager1" runat="server" PagedControlID="listItems" QueryStringField="page"

PageSize="5">

<Fields>

<asp:NumericPagerField />

</Fields>

</asp:DataPager>

</div>

</form>

</

body>

</

html>

Friday, July 17, 2009

Find String within string C#

int FirstChr = MainString.IndexOf(SearchString);
 

Thursday, July 16, 2009

Date formating at gridview

DataFormatString

="{0:dd-MM-yyyy}"

Connection string based on the Database Environment c#

 Connection string based on the Database Environment c# sample:
 
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml">

<

head runat="server">

<title>Untitled Page</title>

</

head>

<

body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<div>

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ProviderName="System.Data.SqlClient"

DataSourceMode="DataReader"

SelectCommand="SELECT * FROM [mntsold]"></asp:SqlDataSource>

</div>

</form>

</

body>
</
html>
 

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

{

protected void Page_Load(object sender, EventArgs e)

{

if (System.Environment.GetEnvironmentVariable("COMPUTERNAME").ToString() == "xxxxxxx")

{

Response.Write(

"from test database");

SqlDataSource1.ConnectionString =

ConfigurationManager.ConnectionStrings["JDE_RKConnectionString"].ConnectionString;

}

if (System.Environment.GetEnvironmentVariable("COMPUTERNAME").ToString() == "ITWEB1223")

{

Response.Write(

"from production database");

SqlDataSource1.ConnectionString =

ConfigurationManager.ConnectionStrings["JDE_PRODUCTIONConnectionString"].ConnectionString;

}

 

}

}

SQLdatasource Connection String in code behind c#

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ProviderName="System.Data.SqlClient"

DataSourceMode="DataReader"

SelectCommand="SELECT * FROM [mntsold]"></asp:SqlDataSource>

code behind:

SqlDataSource1.ConnectionString =

ConfigurationManager.ConnectionStrings["JDE_PRODUCTIONConnectionString"].ConnectionString;

web.config

<

connectionStrings>

<

add name="JDE_PRODUCTIONConnectionString" connectionString="Data Source=ENTERPRISE;Initial Catalog=JDE_PRODUCTION;User ID=sssss;password=sssss"

providerName="System.Data.SqlClient" />

</
connectionStrings>



Machine Name in code behind C#

string name = System.Environment.GetEnvironmentVariable("COMPUTERNAME");