Monday, June 15, 2009

Gridview Template, Data-Binding in a Template asp.net

Gridview Template, Data-Binding in a Template asp.net



<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="Employee ID" ReadOnly="true"/>
<asp:BoundField DataField="FirstName" HeaderText="First Name"/>
<asp:BoundField DataField="LastName" HeaderText="Last Name"/>
<asp:TemplateField HeaderText="Birth Date">
<ItemTemplate>
<asp:Label ID="BirthDateLabel" Runat="Server"
Text='<%# Eval("BirthDate", "{0:d}") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:Calendar ID="EditBirthDateCalendar" Runat="Server"
VisibleDate='<%# Eval("BirthDate") %>'
SelectedDate='<%# Bind("BirthDate") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField Text="Show Detail"
DataNavigateUrlFormatString="~/ShowEmployeeDetail.aspx?EmployeeID={0}"
DataNavigateUrlFields="EmployeeID" />
</Columns>


Source: http://msdn.microsoft.com/en-us/library/ms228046.aspx

Build your own Whois Lookup with ASP.NET and jQuery

Build your own Whois Lookup with ASP.NET and jQuery

.NET - Programmatically manipulating web.config in ASP.NET 2.0 and ASP.NET 3.5

.NET - Programmatically manipulating web.config in ASP.NET 2.0 and ASP.NET 3.5

Friday, June 12, 2009

RSS Feed, Affiliate Link Capture on Same Page - C#

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.
 
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
   <script language = "C#" runat="server">

      ICollection CreateDataSource()
      {
         DataTable dt = new DataTable();
         DataRow dr;

         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));

         for (int i = 0; i < 10; i++)
         {
            dr = dt.NewRow();
            dr[0] = "Item " + i.ToString();
            dt.Rows.Add(dr);
         }

         DataView dv = new DataView(dt);
         return dv;
      }

      void Page_Load(Object sender, EventArgs e)
      {
         if (!IsPostBack)
         {
            DataList1.DataSource = CreateDataSource();
            DataList1.DataBind();
         }
      }

      void Button_Click(Object sender, EventArgs e)
      {
         if (DataList1.Items.Count > 0)
         {
            Label1.Text = "The Items collection contains: <br />";

            foreach(DataListItem item in DataList1.Items)
            {

               Label1.Text += ((DataBoundLiteralControl)item.Controls[0]).Text +
                              "<br />";
            }
         }
      }

   </script>

<head runat="server">
    <title>DataList Items Example</title>
</head>
<body>

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

      <h3>DataList Items Example</h3>

      <asp:DataList id="DataList1" runat="server"
           BorderColor="black"
           CellPadding="3"
           Font-Names="Verdana"
           Font-Size="8pt">

         <HeaderStyle BackColor="#aaaadd">
         </HeaderStyle>

         <AlternatingItemStyle BackColor="Gainsboro">
         </AlternatingItemStyle>

         <HeaderTemplate>

            Items

         </HeaderTemplate>

         <ItemTemplate>

            <%# DataBinder.Eval(Container.DataItem, "StringValue") %>

         </ItemTemplate>

      </asp:DataList>

        <br /><br />

      <asp:Button id="Button1"
           Text="Display Contents of Items Collection"
           OnClick="Button_Click"
           runat="server"/>

      <br /><br />

      <asp:Label id="Label1"
           runat="server"/>

   </form>

</body>
</html>

Sourcse: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.items.aspx

Building Cascading DropDownList in ASP.Net Using jQuery and JSON

Building Cascading DropDownList in ASP.Net Using jQuery and JSON

Wednesday, June 10, 2009

Redirect URL using 301 redirection for affiliate Marketing

Redirect URL using 301 redirection for affiliate Marketing

Method 1.
 protected void Page_Load(object sender, EventArgs e)
    {
 Response.Status = "301 Moved Permanently";
 Response.AddHeader("Location", NEW_URL);

    }

Method 2.
protected void Application_BeginRequest(Object sender, EventArgs e)
  {
   string sOldPath = HttpContext.Current.Request.Path.ToLower();
   

   string sPage = "http://www.aspcode.net/articles/" + sOldPath;
   Response.Clear();
   Response.Status = "301 Moved Permanently";
   Response.AddHeader("Location",sPage);
   Response.End();
  }

Method 3.

protected override void OnInit(EventArgs e)
{
    int i = Request.Url.ToString().IndexOf("www.");
    if (i < 8 && i != -1)
    {
        Response.Clear();
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location", Request.Url.ToString().Remove(i, 4));
        Response.End();
    }
    base.OnInit (e);
}

 

 

.NET - Read Data From an Excel File (.xls) in ASP.NET

.NET - Read Data From an Excel File (.xls) in ASP.NET

Tuesday, June 9, 2009

Using RoleService for Role Based Forms Authentication in ASP.NET AJAX

Using RoleService for Role Based Forms Authentication in ASP.NET AJAX

Google Checkout Custom Control

Google Checkout Custom Control
Google recently introduce Google Checkout. "Google Checkout is a checkout process that you integrate with your website, enabling your customers to buy from you quickly and securely, using a single username and password. Once they do, you can use Google Checkout to charge their credit cards, process their orders, and receive payment in your bank account."

They currently have no ASP.NET examples posted on their site so I have created an ASP.NET 2.0 Custom Web Control that will allow you to easily integrated with their service by simply dropping a control on the page a specifying a few parameters. So here it is...


http://www.c-sharpcorner.com/UploadFile/jlf0002/googlecheckoutcustomcontrol08072006134735PM/googlecheckoutcustomcontrol.aspx

Tuesday, June 2, 2009

SQL-Server Order by Random

select top 10 * from proddta.f4072 order by newid()