Archive

Archive for January, 2012

Visual Studio Empty Website Data Source window

January 31, 2012 Leave a comment

Hi all,

There is a solution for Empty Website Data Source window

1) Add an aspx page

2) Add ReportViewer control to the new page in design mode

3) Go to design mode–> click the Arrow in the upper right corner and choose Design new report.

4) Now Close it you will find Website Data Source window is not empty

5) Check All References in Bin Folder

Hope this helps

Good Luck

 

Categories: ASP.Net

Find Date between Two Date Range

January 27, 2012 Leave a comment

Hi all,

try this example to find Date between two dates Range

for example i want to display all date of  Saturday and Sunday between two dates


protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack)
 {
 DateTime startDate = new DateTime(2011, 3, 1);
 DateTime endDate = DateTime.Now;
 TimeSpan diff = endDate - startDate;
 int days = diff.Days;
 for (var i = 0; i <= days; i++)
 {
 var testDate = startDate.AddDays(i);
 switch (testDate.DayOfWeek)
 {
 case DayOfWeek.Saturday:
 case DayOfWeek.Sunday:
 Response.Write(testDate.ToShortDateString()+"<br/>");
 break;
 }
 }
 }
 }

Hope this helps

Good Luck

Categories: ASP.Net

Get local computer IP address

January 16, 2012 Leave a comment

Hi all,

try this example to Get local computer IP address we will create a new method which will return IP Address


private string GetLocalIP()
 {
 string _IP = null;
 // Resolves a host name or IP address to an IPHostEntry instance.
 // IPHostEntry - Provides a container class for Internet host address information.
 System.Net.IPHostEntry _IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
 // IPAddress class contains the address of a computer on an IP network.
 foreach (System.Net.IPAddress _IPAddress in _IPHostEntry.AddressList)
 {
 // InterNetwork indicates that an IP version 4 address is expected
 // when a Socket connects to an endpoint
 if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
 {
 _IP = _IPAddress.ToString();
 }
 }
 return _IP;
 }

Hope this helps

Good Luck

Categories: ASP.Net

Pass QueryString Parameter with NavigaterUrl in Hyperlink inside a GridView

January 6, 2012 3 comments

Hi all,

try this example to try many ways to Pass QueryString Parameter with NavigaterUrl in Hyperlink inside a GridView

1-a: Using HyperLinkField of GridView :-


<ASP:GRIDVIEW id=GridView1 runat="server" autogeneratecolumns="False" datakeynames="CustomerID" datasourceid="SqlDataSource1">
 <COLUMNS>
 <ASP:HYPERLINKFIELD text="Detail" datanavigateurlfields="CustomerID" datanavigateurlformatstring="CustomerDetails.aspx?customerId={0}"></ASP:HYPERLINKFIELD>
 <ASP:BOUNDFIELD datafield="CustomerID" headertext="CustomerID" readonly="True" sortexpression="CustomerID"></ASP:BOUNDFIELD>
 <ASP:BOUNDFIELD datafield="CompanyName" headertext="CompanyName" sortexpression="CompanyName"></ASP:BOUNDFIELD>
 <ASP:BOUNDFIELD datafield="ContactName" headertext="ContactName" sortexpression="ContactName"></ASP:BOUNDFIELD>
 </COLUMNS>
</ASP:GRIDVIEW>

<ASP:SQLDATASOURCE id=SqlDataSource1 runat="server" connectionstring="<%$ ConnectionStrings:NORTHWNDConnectionString %>"
selectcommand="SELECT [CustomerID], [CompanyName], [ContactName] FROM [Customers]">
</ASP:SQLDATASOURCE>

1-b: Passing more than one Querystring parameter with HyperLinkField in GridView :-


<asp:hyperlinkfield text="Detail" datanavigateurlfields="CustomerID,CompanyName"
 datanavigateurlformatstring="CustomerDetails.aspx?customerId={0}&amp;companyName={1}" />

2-a: Set NavigateUrl property of HyperLink in TemplateField in Markup :-


<asp:TemplateField>
 <ItemTemplate>
 <asp:HyperLink ID="hlDetails1" Text="Details" runat="server"
 NavigateUrl='<%# "CustomerDetails.aspx?customer=" + Eval("CustomerID") + "&CompanyName=" + Server.UrlEncode(Eval("CompanyName").ToString())%>' />
 </ItemTemplate>
</asp:TemplateField>

2-b: Set NavigateUrl property of HyperLink by Calling method in code-behind:-


<asp:TemplateField>
 <ItemTemplate>
 <asp:HyperLink id="hlDetails2" Text="Details" Runat="server"
 NavigateUrl='<%# GetUrl(Eval("CustomerID"),Eval("CompanyName"))%>' />
 </ItemTemplate>
</asp:TemplateField>

and in code behind add this method


public string GetUrl(object id, object companyname)
 {
 string url = "~/CustomerDetails.aspx?customerid=" + id.ToString() + "&companyname=" +
 Server.UrlEncode(companyname.ToString());
 return url;
 }

2-c: Set NavigateUrl in RowDataBound event :-


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1" onrowdatabound="GridView1_RowDataBound">
<asp:TemplateField>
 <ItemTemplate>
 <asp:HyperLink id="hlDetails2" Text="Details" Runat="server" />
 </ItemTemplate>
</asp:TemplateField>
</asp:GridView>

and in code behind :-


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.DataRow)
 {
 HyperLink hl = (HyperLink)e.Row.FindControl("hlDetails2");
 if (hl != null)
 {
 DataRowView drv = (DataRowView)e.Row.DataItem;
 string id = drv["CustomerID"].ToString();
 string companyname = drv["CompanyName"].ToString();
 hl.NavigateUrl = "~/CustomerDetails.aspx?customerid=" + id.ToString() + "&companyname=" + Server.UrlEncode(companyname.ToString());
 }
 }
}

Hope this helps

Good Luck

Categories: ASP.Net

Use WebService with Javascript to Get Auto DateTime

January 5, 2012 Leave a comment

Hi all,

try this example to Use WebService with Javascript to Get Auto DateTime

1) open vs2008 and create a new web site and add new WebService name it “WebService.asmx” and add this code :-


using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
 [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

public WebService () {

//Uncomment the following line if using designed components
 //InitializeComponent();
 }

[WebMethod]
 public string GetTime()
 {
 return DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss");
 }

}

2) Add new Web Page and in ASPX Design add this :-


<head runat="server">
 <title>Untitled Page</title>
 <script type="text/javascript" language="javascript">
 var interval = 0;
 function pageLoad() {
 callWebService();
 interval = window.setInterval("callWebService()", 3000);
 }

function callWebService() {
 WebService.GetTime(successCallback, failCallback);
 }

function successCallback(result) {
 var divOutput = document.getElementById("divOutput");
 divOutput.innerHTML = result;
 }

function failCallback(error) {
 alert('Error: ' + error.get_exceptionType());
 }

 </script>
</head>
<body>
 <form id="form1" runat="server">
 <asp:ScriptManager runat="server" ID="scriptManager1">
 <Services>
 <asp:ServiceReference Path="~/WebService.asmx" />
 </Services>
 </asp:ScriptManager>
 <div id="divOutput">
 </div>
 </form>
</body>

then run your page you will find time change every 3 sec this is because i call the result from webservice

Hope this helps

Good Luck

Categories: ASP.Net, Javascript