Skip to main content

Posts

Showing posts from March, 2008

GridView Inside GridView

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataRelation.aspx.cs"
Inherits="DataRelation" %>

<%@ Import Namespace="System.Data" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="GridView1"runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundFieldDataField="CompanyName"
HeaderText="CompanyName"/>
<asp:TemplateField>
<ItemTemplate>
<asp:GridViewID="GridView2"
DataSource='<%#((DataRowView)Container.DataItem).CreateChildView("ParentChild") %>'
runat="server"Au…

JavaScript Tips

let us supposed that you have a textbox is clicked, you need the text that says "Enter your search here" to dissappear. This is the javascript for this?. <asp:TextBoxID="TextBox1"runat="server"Text="Serch Here"onkeydown="if (this.value == 'Serch Here') this.value = '';"onclick="this.value=''"></asp:TextBox>

CheckBox OnClick Hide/Show HTML Table

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HideShow.aspx.cs" Inherits="HideShow" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><scripttype="text/javascript">function ShowHide(obj) { if(!obj.checked) { document.getElementById('tbl_QuestionTags_Software').style.display = 'none'; document.getElementById('tbl_QuestionTags_Software').style.visibility="hidden"; } else { document.getElementById('tbl_QuestionTags_Software').style.display = ''; document.getElementById('tbl_QuestionTags_Software').style.visibility =&quo…

Master Detail Using GridView and DetailsView

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewInsideGridView.aspx.cs" Inherits="GridViewInsideGridView" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"AutoGenerateSelectButton="True"DataKeyNames="Id"OnSelectedIndexChanged="GridView1_SelectedIndexChanged"><Columns><asp:BoundFieldDataField="Id"/><asp:BoundFieldDataField="Name"/></Columns></asp:GridView><asp:DetailsViewID="DetailsView1"runat="server"A…

How To Add a User Define Section in Configuration File

ou can create your own configuration section and use one of the staic methods in the System.Configuration namespace to retrieve the information. Attached is a simple example. Also lookup configSection element and IConfigurationSectionHandler interface for additional information.<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserSection.aspx.cs" Inherits="UserSection" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="server"><Columns><asp:BoundFieldDataField="Key"HeaderText="Key"/><asp:BoundFieldDataField="Value"…

How To Add Please Wait message to a Button

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PleaseWaitButton.aspx.cs" Inherits="PleaseWaitButton" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><div><asp:ButtonID="Button1"runat="server"Text="Button"/></div></div></form></body></html>using System; using System.Data; using System.Configuration; using System.Collections; 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; publicpartialclass PleaseWaitButton : System…

change some text before it is sent to the client.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InterceptHtml.aspx.cs" Inherits="InterceptHtml" %> <!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> Hello World! <br /> Hi </div> </form> </body> </html> using System; using System.Data; using System.Configuration; using System.Collections; 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; using System.Text; using System.IO; publicpartialclass I…

How To Add Adding Paging Support to the Repeater or DataList with the PagedDataSource Class

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PagingInRepeater.aspx.cs" Inherits="PagingInRepeater" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="frmTest"method="post"runat="server"><tablewidth="100%"border="0"><tr><td><asp:LabelID="lblCurrentPage"runat="server"></asp:Label></td></tr><tr><td><asp:ButtonID="cmdPrev"runat="server"Text=" << "OnClick="cmdPrev_Click"></asp:Button><asp:ButtonID="cmdNext"runat="server"Text=" >> " OnClick="cmdN…

How To Find Sunday and Monday Between Two Dates

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default13.aspx.cs"
Inherits="Default13" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="grd"runat="server"AutoGenerateColumns="False">
<Columns>
<asp:BoundFieldDataField="Key"HeaderText="Date"/>
<asp:BoundFieldDataField="Value"HeaderText="Date"/>

</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>




using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using S…

DateDiff Function in C#

using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication2 { publicenum DateInterval { Year, Month, Weekday, Day, Hour, Minute, Second } class Program { staticvoid Main(string[] args) { DateTime dt1 = new DateTime(1994, 12, 12); DateTime dt2 = new DateTime(1994, 12, 12); long date = DateDiff(DateInterval.Day, dt1, dt2); Console.Write(date); Console.ReadLine(); } publicstaticlong DateDiff(DateInterval interval, DateTime date1, DateTime date2) { TimeSpan ts = ts = date2 - date1; switch (interval) { case DateInterval.Year: return date2.Year - date1.Year; case DateInterval.Month: return (date2.Month - date1.Month) + (12 * (date2.Year - date1.Year));����������������…

How to count the number of workdays between two dates and exclude holidays and weekends

using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication2 { class Program { staticvoid Main(string[] args) { DateTime dt1 = new DateTime(1994, 12, 12, 12, 11, 33); // Start date Dec 12th DateTime dt2 = new DateTime(1994, 12, 31, 13, 56, 11); // End date Dec 31st List<DateTime> holidays = new List<DateTime>(); holidays.Add(new DateTime(1994, 12, 14)); // Make Dec 14th a holiday Console.WriteLine(dt1.Date.ToShortDateString()); Console.WriteLine(GetWorkingDays(dt1, dt2).ToString()); // without holidays Console.WriteLine(GetWorkingDays(dt1, dt2, holidays).ToString()); // with holidays Console.ReadLine(); } //These crude methods assumes that DateTime b is later than DateTime a//If not they will just quit out and return 0publicstaticint GetWorkingDays(DateTime a, DateTime b) { return G…

How To Use RadioButtonList as DropDownList Alternative

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PopUpRadioList.aspx.cs"
Inherits="PopUpRadioList" %>

<%@ Register TagPrefix="ajaxToolkit" Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<styletype="text/css">
.popupControl
{
background-color:White;
position:absolute;
visibility:hidden;
}
</style>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager>
<asp:DetailsViewID="dvProduct"runat="server"DefaultMode="Ed…

Highlight a Row in GridView without a postback using ASP.NET and JavaScript

Selecting a row in the GridView causes a postback. In order to highlight a row in the GridView, you have to set the ‘SelectedRowStyle’ property which takes effect when the postback occurs. In this article, we will see how to highlight a row without causing a postback. We will be using the RowCreated event of the GridView. A GridViewRow object is created for each row in the control before the GridView is rendered. Whenever a row in the GridView gets created, the RowCreated event is fired. Using this event, we can customize the behavior of the GridView. For e.g.: adding client script to the row or customizing the content of the row. Let us see an example where we will be adding some client script to the GridView. I assume that you have some experience of creating data sources and binding controls to it. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewSelect.aspx.cs" Inherits="GridViewSelect" %><!DOCTYPEhtmlPUBLIC"-//W…

How To Split String and Display in GridView

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SplitFunctionUsingRegx.aspx.cs" Inherits="SplitFunctionUsingRegx" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div> Original String<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox><br/> Separator<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox><br/><asp:ButtonID="btnConvert"runat="server"Text="Split"OnClick="btnConvert_Click"/><asp:GridViewID="GridView1"runat="server"></asp:GridView></div></form&g…

How To Change GridView Header Text At Runtime

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChangeHeaderAtRuntime.aspx.cs" Inherits="ChangeHeaderAtRuntime" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><div><asp:GridViewID="GridView1"runat="server"OnRowCreated="GridView1_RowCreated"></asp:GridView></div></div></form></body></html>using System; using System.Data; using System.Configuration; using System.Collections; 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.HtmlCo…