Several times there is a requirement to hide/disable the close button and to close the Form with a button on the Form to exit the application.

To hide the Close Button on the form we can set ControlBox propertyof the Form to False (by default its set to True)

Posted by SushilaSB | 20 comment(s)
Filed under:

VB.NET

Private Sub MonthCalendar1_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged

'Display the dates for selected range
Label1.Text = "Dates Selected from :" & (MonthCalendar1.SelectionRange.Start() & " to " & MonthCalendar1.SelectionRange.End)

'To display single selected of date
'MonthCalendar1.MaxSelectionCount = 1

'To display single date use MonthCalendar1.SelectionRange.Start/ MonthCalendarSelectionRange.End
Label2.Text = "Date Selected :" & MonthCalendar1.SelectionRange.Start

End Sub

C#

private void MonthCalendar1_DateChanged(object sender, System.Windows.Forms.DateRangeEventArgs e)
{
//Display the dates for selected range
Label1.Text = "Dates Selected from :" + (MonthCalendar1.SelectionRange.Start() + " to " + MonthCalendar1.SelectionRange.End);

//To display single selected of date
//MonthCalendar1.MaxSelectionCount = 1;

//To display single selected of date use MonthCalendar1.SelectionRange.Start/ MonthCalendarSelectionRange.End
Label2.Text = "Date Selected :" + MonthCalendar1.SelectionRange.Start;
}

Posted by SushilaSB | 8 comment(s)
Filed under:

Join the Windows Community Site!

Please register and share your comments/suggestion.

http://www.merawindows.com

A great effort put together by fellow MVP's: Raghu Boddu, Soumitra Sengupta and M Rajesh

Posted by SushilaSB | 1 comment(s)

We come across situation many a times where we need the name of the folder in which the file resides. Let's say the folder is as "C:\Project1\CSProj1\somename\file1.cs"

We need to get the folder "somename"

We can do this by using the namespace System.IO. Code goes as below

VB.NET

Dim file As FileInfo = New FileInfo("C:\Project1\VBProj1\somename\file1.vb")
Response.Write(file.Directory & "<br>")  'O/P -> C:\Project1\VBProj1\somename
Response.Write(file.Directory.Name)      'O/P -> somename

C#

FileInfo file = new FileInfo(@"C:\Project1\CSProj1\somename\file1.cs");
Response.Write(file.Directory + "<br>");  //O/P -> C:\Project1\CSProj1\somename
Response.Write(file.Directory.Name);     //O/P -> somename

More about FileInfo members

Posted by SushilaSB | 21 comment(s)
Filed under:

VB.NET

Shared Function ExtractNumbers( ByVal expr As String ) As String
 Return String.Join( Nothing, System.Text.RegularExpressions.Regex.Split( expr, "[^\d]" ) )
End Function

C#

static string ExtractNumbers( string expr )
{
 return string.Join( null,System.Text.RegularExpressions.Regex.Split( expr, "[^\\d]" ) );
}

Call the function as follows

VB.NET

Response.Write ( ExtractNumbers( "12EFR77" ) )

C# 

Response.Write ( ExtractNumbers( "12EFR77" ) );

Posted by SushilaSB | 29 comment(s)
Filed under:

To open pop-up window using <asp:dropdownlist..>

VB.NET

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
 Response.Write("<script>window.open('" + DropDownList1.SelectedValue + "');</script>")
End Sub

C#

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("<script>window.open('" + DropDownList1.SelectedValue + "');</script>");

To pop-up using client-side event

VB.NET

DropDownListID.Attributes("onchange") = "<open pop up here>"

C#

DropDownListID.Attributes("onchange") = "<open pop up here>";

Posted by SushilaSB | 5 comment(s)
Filed under:

We have seen many examples on how to change the background color of row based on the data using DataGrid Control. This can be done using a helper function or using the appropriate event of the datagrid

We will use the similar scenerio to find out how to use GridView Control in such case.

Step 1: Drag Drop GridView Control

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

Step 2: We will use SqlDataSource control for the connectivity with the Sql Database

Lets use web.config for Sql Connection string:

<connectionStrings>

connectionStrings>

<add name="DummyDB" connectionString="Server=localhost;Integrated Security=True;Database=DummyDB;Persist Security Info=True" providerName="System.Data.SqlClient" />

</connectionStrings >

</connectionStrings >

The connection string is used with the Sql Datasource control as follows in the respective page

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DummyDB %>" SelectCommand="Select * from products"></asp:SqlDataSource>

Step 3:  We have Products table with field Unitprice as one of the fields. We will change the row background color to red if the UnitPrice<10

Step 3:  We have Products table with field Unitprice as one of the fields. We will change the row background color to red if the UnitPrice<10

This is done using the RowDataBound event

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

</asp:GridView>

Step 4: We will code as follows for the RowDataBound Event.

VB.NET

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

   If e.Row.RowType = DataControlRowType.DataRow Then

      If (e.Row.DataItem("UnitsInStock") < 20) Then

         e.Row.BackColor = Drawing.Color.Red

      End If

   End If

End Sub

Thats All!

 

Posted by SushilaSB | 30 comment(s)
Filed under:

Virtual India is a research project by Microsoft Research India, in collaboration with the Government of India's Department of Science and Technology, powered by Microsoft Virtual Earth™ technology.

Check below links for more information on:

With Virtual India one can view maps in Hindi, English, Kannada and Tamil.

Posted by SushilaSB | 1 comment(s)
Filed under:

In this Sample code we will see how to customize calendar control to limit the user to select the day on or after today

Step 1: Drag Drop Calendar Control

<asp:Calendar id="Calendar1"  runat="server"></asp:Calendar>

Step 2: In code behind use the below code in DayRender Event

The DayRenderEventArgs object contains two properties that you can use to programmatically control the format of the date cell. The Cell property represents the cell being rendered, while the Day property represents the date to render in the cell.

Set the Day's IsSelectable property to true or false depending on the criteria. In this code sample we will limit user to select day on or after today.

VB.NET Code

Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender

e.Day.IsSelectable = e.Day.Date >= DateTime.Now

End Sub

C# Code

void OnDayRender (Object sender, DayRenderEventArgs e)

{

e.Day.IsSelectable = e.Day.Date >= DateTime.Now;

}

Posted by SushilaSB | 1 comment(s)
Filed under:

Check out Tours and Demos of much awaited Microsoft Expression Series

Posted by SushilaSB | with no comments
Filed under:
More Posts « Previous page - Next page »