How to add item into the listBox in windows phone

July 31, 2014 0 Comments


ListBox is a container in which we can add strings. User can select by clicking. Article contain different topics , these are
 1. Add ListBox Control with items using XAML
 2. Add ListBox Control in code file


There are some basic steps to complete that tasks
Add ListBox control with items using XAML
Step-1 :  Add ListBox control in contentPanel using xaml code , now your code llok like
<ListBox x:Name=" ListBox1" >
 </ListBox>
Step-2 :  Open ListBox properties and select Items(collection) ellipse symbol. After pressing ellipse button , A new window will appear
Open ListBox properties and select Items

Step-3 :  Using Object Collection Editor, add controls to the List Box by selecting controls from Dropdown List.
Object Collection Editor


Step-4  : After adding controls, you can assign content property of them.
Step-5 : Now, Press Ok button after adding items.
Step-6 : Now , Your complete code look like

<ListBox x:Name=" L1" >
                <ListBoxItem Content="Apple"/>
                <ListBoxItem Content="Mango"/>
                <CheckBox Content="Male" IsChecked="True"/>

            </ListBox>

Code Generate the following output

How to add item into the listBox in windows phone

0 comments:

Getting started with windows phone App C#

July 30, 2014 0 Comments

Now start code with windows phone, first to develop app in windows phone. Get the tool you need, build your first app and test it in your system simulator. you can run this in your phone also. Before learning this article, must to learn XAML syntax. After that you can easily transfer your skills to develop windows phone app that use xaml for the UI and c#. 

 

This topic contains the following sections.

Get set up
Create your first app
Get set up
Download the Windows Phone SDK 8.0, which includes all the tools you need to create Windows Phone apps: Microsoft Visual Studio Express 2012 for Windows Phone, project templates for creating new Windows Phone apps, the Windows Phone emulator for testing, and more.
Create your first app

he first step in creating a Windows Phone app is to create a new project in Visual Studio.
To create the project

  1. Make sure you’ve downloaded and installed the Windows Phone SDK. 
  2. Launch Visual Studio from the Windows Start screen. If the Registration window appears, you can register the product, or you can temporarily dismiss the prompt.
  3. Create a new project by selecting the FILE | New Project menu command.
  4. In the New Project window, expand the installed Visual C# or Visual Basic templates, and then select the Windows Phone templates.
  5. In the list of Windows Phone templates, select the Windows Phone App  template.Create your first app
  6. Add TextBlock from toolBox into ContentPanel, now your code look like

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Hello World!" FontSize=" 30" VerticalAlignment="Top"/>

        </Grid>

Code Generate the following output


Getting started with windows phone App C#

0 comments:

How to Submit data on DropDown Selection changed in MVC Razor

Submitting the form by button, programmer have to assign only the type of that button and on click this button all the data can be get on the server side. On drop-down change we have manually submit the form by either specifying "OnSelectionChanged" event or some jquery functions.

In earlier article I have created DropDownList in MVC, to submit the form we can simply use only submit function on change event of the list.

@Html.DropDownList("ddlname", "List to bind", "--default title--", new { onchange = "submit();" })

After writing this code on change it will post all the data on the form to server-side but programmer have to use same name in action method as used here “ddlname”. When we use view-model to bind the data then dropdown list’s code will be changed as:

@Html.DropDownListFor(model => model.Property , "List to bind", "--default title--", new { onchange = "submit();" })

This code will contains the value of the property of model as used here. The value will submit on change the selection of this drop-down list. Programmer can change other controls value by using this code.

Suppose we have to select country, state and city on the form in hierarchy manner. On change the country, states drop-down list should change and on change of state, city drop-down list should change. By implement this functionality we can use this submit functionality.

0 comments:

How to Use Multiple Submit Button in MVC Razor

July 30, 2014 , , , 0 Comments

The most common method to get the data on server from client side. Submit button on the form can be used to post all the form data to be used further by programmer. Generally one form only have a single submit because of user want to post data only once.

To submit data in different ways programmer can use more than one submit button. A form can have multiple submit buttons as per the requirement of programmer. We can send the button’s name on the button click.

The action should have the same name of the button to get the value of clicked button. Suppose all the button’s have same name as submit as written below:

<input type = "submit" name = "btnsubmit" value= "submit1" />
<input type = "submit" name = "btnsubmit" value= "submit2" />
<input type = "submit" name = "btnsubmit" value= "submit3" />

Now in controller’s action the variable should be of string type and name as “submit” as below:

[HttpPost]
public ActionResult SubmitData(string btnSubmit)
{
If (btnSubmit == "submit1")
{
//code to execute
}

If (btnSubmit == "submit2")
{
//code to execute
}

If (btnSubmit == "submit3")
{
//code to execute
}
}

According to this code we can implement different functionality on each submit button with all the data posted on the form. These button will only post the data containing as input on the form and also inside the form element.

0 comments:

How to add Hyperlink button control by using code in windows phone

July 28, 2014 0 Comments

In previous article we have already learned about  Hyperlink Button control.  Using the HyperlinkButton control you can navigate one page to another in windows phone. The following example creates a HyperlinkButton control named hyper and then adds it to ContentPanel grid.

To add the Hyperlink Button control by using code

Open MainPage.xaml.cs.

Add the following code in the constructor.
C#

public MainPage()
        {
            InitializeComponent();
            HyperlinkButton h1 = new HyperlinkButton();
            h1.Content = "My Button";
            ContentPanel.Children.Add(h1);
            h1.Click += new RoutedEventHandler(HyperlinkButton_Click);


            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();

        }

 private void HyperlinkButton_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/secondpage.xaml", UriKind.Relative));
        }

Create Hyperlink Button control instance , assign string to the content property of Hyperlink Button. Now add this control into Content Panel. When we click on it then page navigate to other page. The name of other page is "secondpage.xaml". So raise click event for that, using NavigationService.Navigate ( ) method you can move one page to another.

Code generate the following code

How to add Hyperlink button control by using code in windows phoneHow to add Hyperlink button control by using code in windows phone


0 comments:

How to add a Hyperlink Button control to a page in Windows Phone 8

July 26, 2014 0 Comments

This topic describes the various ways to add a Hyperlink Button control to a Windows Phone 8 project. The Hyperlink Button control is part of the libraries in Windows Phone SDK 8.0.
This topic contains the following sections.

  1. Adding a Hyperlink Button control by using the Toolbox.
  2. Adding the Hyperlink Button control by using XAML.
  3. Adding the Hyperlink Button control by using code.

Adding a Hyperlink Button control by using the Toolbox

The easiest way to add a Hyperlink Button control and reference it properly is to drag it from the Toolbox and drop it to your XAML designer or XAML view.

To add a Hyperlink Button control from the Toolbox
  1. In the HyperlinkApplication project, open the Toolbox, and then open the All Windows Phone Controls.
  2. From the Toolbox, drag the HyperlinkButton control to the XAML or designer view.Visual Studio performs the following tasks automatically.
In the <phone:PhoneApplicationPage> start tag of the XAML page.
Adds the following XAML if you drag the control to the design view.

<HyperlinkButton Content="HyperlinkButton" HorizontalAlignment="Left" Margin="103,213,0,0" Grid.Row="1" VerticalAlignment="Top"/>

    3. Add single attribute in HyperlinkButton tag, which is NavigateUri="http://www.google.com".
    4. Must Add TargetName property with the NavigateUri property, if you use this for external url. It does not matter what value you use for this property.  Now your complete code look like

<HyperlinkButton TargetName="Google" NavigateUri="http://www.google.com/" Content="HyperlinkButton" HorizontalAlignment="Left" Margin="103,213,0,0" Grid.Row="1" VerticalAlignment="Top"/>

Code generate the following output

How to add a Hyperlink Button control to a page in Windows Phone 8How to add a Hyperlink Button control to a page in Windows Phone 8

0 comments:

How to get back date from current date in ASP.NET C#

July 22, 2014 0 Comments

If you want to find back date from current date then you should take DateTime Structure with add days method. Through this method we can add some days in existing date. But if we pass minus sign(-) with integer value  in add days method then you get back date. lets take a simple example.

Complete Code

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        DateTime currentdate = DateTime.Now;
        Label1.Text = currentdate.ToString()+"<br/>";
        Label1.Text += "before 3 days " + currentdate.AddDays(-3);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Get back Date</title>
</head>
<body>
    <form id="form1" runat="server">
  <div>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <br />

        <asp:Button ID="Button1" runat="server" Text="Get Back Date" OnClick="Button1_Click" />
    </div>
    </form>
</body>
</html>

Code Generate the following output



Download Source Code

0 comments:

How to Perform Searching Data by Using a Full-Text Search

July 20, 2014 , , , , 1 Comments

After the full-text index has been created on a table, you can query the table by using the full-text predicates. The full-text predicates are used to specify how the search string should be searched in the table.
Predicates can be used to enhance the search so that the result have so focus on the search criteria. Sql programming have a list of predicates to be used.

The following predicates can be used while performing the full-text search:

FREETEXT: When the search criteria are given, FREETEXT searches for any variation of a word or a group of words given in the search column. FREETEXT is used for the prefix searches.
Considering the previous scenario of the bike racing competition, you can use the FREETEXT predicate to obtain the desired output, as shown in the following statement:

SELECT Description FROM Production.ProductDescription WHERE FREETEXT (Description, ‘race winners’)

CONTAINS: This predicate is used in queries when you want to search for a specific phrase or for the exact match. It also searches for the proximity of words within a text. For example, you can use the following statement to search for the words ‘Ride’ near the word ‘Bike’ in the ProductDescription table:

SELECT Description FROM Production.ProductDescription
WHERE CONTAINS (Desctiption, ‘ride NEAR bike’)

1 comments:

Populating the Full-Text Index in Search: SQL Server

July 20, 2014 , , , , 0 Comments

After creating the full-text index, you need to populate it with the data in the columns enabled for full-text support. The SQL Server full-text search engine populates the full-text index through a process called population. Population involves filling the index with words and their location in the data page. When a full-text index is created, it is populated by default. In addition, the SQL Server automatically updates the full-text index as the data is modified in the associated tables.

However, the SQL Server does not keep a list of changes made to the indexed data when the CHANGE_TRACKING option is off. This option is specified while creating the full-text index by using the CREATE FULLTEXT INDEX statement.

If you do not want the full-text index to be populated when it is created using the CREATE FULLTEXT INDEX statement, then you must specify NO POPULATION along with the CHANGE TRACKING OFF option. To populate the index, you need to execute the ALTER FULLTEXT INDEX command along with the START FULL, INCREMENTAL, or UPDATE POPULATION clause.

For example, to create an empty full-text index on the ProductDescription table, you can execute the following statement:

CREATE FULLTEXT INDEX ON Production. ProductionDescription (Description)
KEY INDEX PK_ProductDescription_ProductDescriptionID
WITH CHANGE_TRACKING OFF, NO POPULATION

To populate the index you need to execute the following statement:
ALTER FULLTEXT INDEX ON Production. ProductDescription START FULL POPULATION

The preceding statement will populate the full-text index created on the ProductDesctiption table.

Similar to regular SQL indexes, full-text indexes can also be updated automatically as the data is modified in the associated tables. This repopulation can be time-consuming and adversely affect the usage of resources of the database server during periods of high database activity. Therefore, it is better to schedule repopulation of full-text indexes during periods of low database activity. You can specify the following types of full-text index population methods to repopulate the index:

Full Population

You can use this method when you need to populate the full-text catalog or the full-text index for the first time. After that, you can the maintain the indexes by using change tracking or incremental populations.
During a full population of a full-text catalo, index entries are built for all the rows in all the tables covered by the catalog. If a full population is requested for a table, index entries are built for all the rows in that table.

Change Tracking-Based Population

The SQL Server maintains a record of the rows that have been modified in a table set up for full-text indexing. These changes are propagated to the full-text index.

Incremental Timestamp-Based Population

The incremental population method updates the full-text index with the data that has been changed since the last time the index was refreshed. For an incremental population refresh to work, the indexed table must have a column of the timestamp data type. If a table does not have a column of the timestamp data type, then only a full population refresh can be done.

0 comments:

Configuring Full-Text Search in SQL Server

July 20, 2014 , , , , 0 Comments

The full-text query feature in the SQL Server enables users to search for a wide range of text in the SQL tables. Consider an example. The sales management team of AdventureWorks, Inc. makes frequent searches on the ProductDescription table to develop marketing strategies. The search is based on the data stored in the Description column of the table.

A bike racing competition is scheduled to begin in Texas. The sales manager of AdventureWorks wants to see the details of all the bikes that are related to racing, so that a marketing strategy can be designed to increase the sale of these bikes. Specifically, he wants a list of all the bikes that have the keyword ‘race winner’ in the description.

As the data is large, the search query takes a long time to retrieve data from the table. In this scenario, you can apply a full-text index on the Description column of the ProductDescription table to improve the speed of searching.

To retrieve the required details by using full-text search, you need to configure full-text search on the database. For this, you need to perform the following tasks:
  • Enable the full-text search in the database.
  • Create a full-text catalog.
  • Create a unique index.
  • Create a full-text index.
  • Populate the full-text index.

Enabling the Full-Text Search in the Database

Before using the full text search feature of the SQL Server, you need to enable the database using the following statement:
USE AdventureWorks
GO
Sp_fulltext_database enable
GO

Creating a Full-Text Catalog

A full-text catalog serves as a container to store full-text indexes. After enabling the full text search, you need to create a full-text catalog. A full-text catalog is a container that contains full-text indexes. A full-text catalog may have multiple full-text indexes. You can create a full-text catalog by using the following command:
CREATE FULLTEXT CATALOG cat1 AS DEFAULT

Creating a Unique Index

After creating the full-text catalog, you need to identify a unique index on the table. This unique index will be mapped to the values in the full-text index. You can use an existing unique index defined on the table, or create a new one. For example, you can create a unique index on the Production.ProductDescription table, as shown in the following statement:

CREATE UNIQUE INDEX Ix_Desc ON Production.ProductDescription
(ProductDescriptionID)

Creating a Full-Text Index

After you have created the full-text catalog and a unique index, you can create a full-text index on the table. A full-text index stores information about significant words and their location within a given column. You can use this information to compute full-text queries that search for rows with particular words or combinations of words. Full-text indexes can be crated on the base tables but not on the views or the system tables.

There are certain words that are used often and may hinder a query. These words are called noise words and are excluded from the search string. For example, if you search string is “Who is the governor of California”, a full-text search will not look for words, such as ‘is’ and ‘the’. Some noise words are a, an, the, and are.

Based on the preceding scenario, you can create a full-text index on the ProductionDescription table. This index is based on the lx_desc index created earlier on the Description column of the table.
Note: You can also create full-text index in the Object Explorer window by right-clicking the table, on which you need to create the full-text index, and selecting Full-Text index-Define Full-Text Index.

0 comments:

Altering, Dropping and Renaming Views in SQL Server

July 20, 2014 , , , 0 Comments

In addition to creating view in sql server, database developer also need to manage them. Management of a view includes altering, dropping, or renaming described below.

Altering views

If you define a view with a SELECT * statement and then alter the structure of the underlying tables by adding columns, the new columns do not appear in the view. Similarly, when you select all the columns in a CREATE VIEW statement, the columns list is interpreted only when you first create the view. To add new columns in the view, you must alter the view.

You can modify a view without dropping it. This ensures that permissions on the view are not lost. You can modify a view without affecting its dependent objects. To modify a view, you need to use the ALTER VIEW statement. The syntax of the ALTER VIEW statement is:

ALTER VIEW view_name [ (column_name) ]
[WITH ENCRYPTION]
AS select_statement
[WITH CHECK OPTION]
Where,

  • View_name specifies the view to be altered.
  • Column_name specifies the name of the column(s) to be used in a view.
  • WITH ENCRYPTION option enerypts the text of the view in the syscomments view.
  • AS specifies the action to be performed by the view.
  • Select_statement specifies the SELECT statement that defines a view
  • WITH CHECK OPTION forces the data modification statements to follow the criteria given in the SELECT statement.

For example, you created a view to retrieve selected data from the Employee and EmployeeDepartmentHistory tables. You need to alter the view definition by including the LoginID attribute from the Employee table.

To modify the definition, you can write the following statement:

ALTER VIEW vwEmployeeDepData
AS
SELECT e.EmployeeID, LoginID, MaritalStatus, DepartmentID
FROM HumanResources.Employee e JOIN
HumanResources.EmployeeDepartmentHistory d
ON e.EmployeeID = d.employeeID

The preceding code alters the view definition by including the LoginID attribute from the Employee Table.

Dropping Views

You need to drop a view when it is no longer required. You can drop a view from a database by using the DROP VIEW statement. When a view is dropped, it has no effect on the underlying table(s). Dropping a view removes its definition and all the permissions assigned to it.

Further, if you query any view that references a dropped table, you receive an error message. Dropping a table that references a view does not drop the view automatically. You have to use the DROP VIEW statement explicitly.
The syntax of the DROP VIEW statement is:  DROP VIEW view_name

For example, you can use the following statement to remove the vwEmployeeDepData view:
DROP VIEW vwEmployeeDepData

The preceding statement will drop the vwEmployeeDepData view from the database.

You can drop multiple views with a single DROP VIEW statement. The names of the view that need to be dropped are separated by commas in the DROP VIEW statement

Renaming Views

At times, you might need to change the name of a view. You can rename a view without dropping it. This ensures that permissions on the view are not lost. A view can be renamed by using the sp_rename system stored procedure.
The syntax of the sp_rename procedure is:  Sp_rename old_viewname, new_viewname
Where,

  • Old_viewname is the view that needs to be renamed.
  • New_viewname is the new name of the view.

For example, you can use the following statement to rename the vwSal view:
Sp_rename vwSal, vwSalary

The preceding command renames the vwSal view as vwSalary.

While renaming views, you must ensure the following:

  • The view must be in the current database.
  • The new name for the view must follow the rules for identifiers.
  • The view can only be renamed by its owner.
  • The owner of the database can also rename the view.

0 comments:

How to Implement Custom Role Provider in Asp.Net MVC

July 20, 2014 , , , , 0 Comments

As I have discussed in earlier article that programmer need to implement custom provides to enable its own database works with in-built functionality. My previous article was to implement custom membership provider and in this article I will continue with custom role provider in MVC.

By following these simple steps we will complete the task:

  • Create a class "Custom_RoleMembership" in Models folder in your MVC application.
  • Inherit this from RoleProvider class exists in "System.Web.Security" namespace.
  • Right click on RoleProvider and select on “Implement Abstract Class”, it will all the override function need to be implement by us.
  • Just implement GetRolesForUser(string username) method and replace that function with the following code:

    public override string[] GetRolesForUser(string username)
    {
    //Get roles for this username and return in string array
    if(username=="admin")
    return new string[] { "Admin" };
    return null;
    }


  • Go to HomeController and place an attribute like below:

    [Authorize(Roles = "Admin")]
    public ActionResult Index()
    {
    ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
    return View();
    }
  • Open web.config file and place below code under system.web tag

    <roleManager defaultProvider="Custom_RoleMembership" enabled="true">
      <providers>
    <clear />
    <add name="Custom_RoleMembership"
    type="CustomMembershipP.Models.Custom_RoleMembership"  />
      </providers>
    </roleManager>

Now run the application and open Index page, it will redirect you on login view. Login with username = admin and password = password and debug this application, it will check the above method GetRolesForUser(). If there is a role for this user then it will go to index view otherwise return to login page.

In my case I have used only one username and return admin only from the method. But you can check the roles in your database and return them in string array. If there is a role “admin” in your array then only it will open index page.

0 comments:

How to Implement Custom Membership in Asp.Net MVC

July 19, 2014 , , , , 0 Comments

In Asp.Net MVC, default membership works with pre-defined/specified data source where programmer don’t worry about anything related to authentication. To implement authentication with desired data source, programmer must implement custom membership as explained in the article. Using custom membership, programmer can easily authenticate user’s visit through self-written code.

This article will describe some simple steps to complete the task:

  • Create a class named "Custom_Membership" in Models folder in your MVC application.
  • Inherit this from MembershipProvider class exists in “System.Web.Security” namespace.
  • Right click on MembershipProvider and select on “Implement Abstract Class”, it will all the override function need to be implement by us.
  • Just implement ValidateUser() method and replace that function with the following code:

    public override bool ValidateUser(string username, string password)
    {
    if (username == "admin" && password == "password")
    {
    return true;
    }
    return false;
    }

  • Go to AccountController >> Login action and change the login functionality as:

    public ActionResult Login(LoginModel model, string returnUrl)
    {
    if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password))
    {
    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
    return RedirectToLocal(returnUrl);
    }
    ModelState.AddModelError("", "The user name or password provided is incorrect.");
    return View(model);
    }

  • Open web.config file of the root and add following in system.web tag

    <membership defaultProvider="Custom_Membership">
      <providers>
    <clear/>
    <add name="Custom_Membership"
    type="CustomMembershipP.Models.Custom_Membership"/>
      </providers>
    </membership>
Run the MVC application and open Login page, it provide an error related to membership, to resolve through error just delete “[InitializeSimpleMembership]” attribute from AccountController.

Again run the application and enter username and password as provided above in ValidateUser() function. It will login successfully, now you can override any of the function in your custom membership class.

0 comments:

How to change text color from ARGB value in ASP.NET

July 17, 2014 0 Comments

ARGB( ) takes four integer input parameter as a argument. Method name explain all things automatically. This name contain four color code, first "A" for Alpha which take 0-255 integer value. Similarly "R" for RED , "G" for Green and "B" for blue. Now lets take an simple example of ARGB( ) method.

How to change text color from ARGB value in ASP.NETSource code

<form id="form1" runat="server">
    <div>
    
        Enter Alpha Color code :
        <asp:TextBox ID="TextBox1" runat="server" Width="190px"></asp:TextBox>
        <br />
        Enter Red Color Code&nbsp;&nbsp;&nbsp; :<asp:TextBox ID="TextBox2" runat="server" Width="190px"></asp:TextBox>
        <br />
        Enter Green Color Code:<asp:TextBox ID="TextBox3" runat="server" Width="190px"></asp:TextBox>
        <br />
        Enter Blue Color Code&nbsp;&nbsp; :
        <asp:TextBox ID="TextBox4" runat="server" Width="190px"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click to change " Width="95px" />
        <br />
    
    </div>
        <asp:Label ID="Label1" runat="server" Font-Size="20pt" Text="Result Label "></asp:Label>
    </form>

CodeBehind Code



protected void Button1_Click(object sender, EventArgs e)
    {
       
        int alpha = int.Parse (TextBox1.Text);
        int red = int.Parse (TextBox2.Text);
        int green = int.Parse (TextBox3.Text);
        int blue =int.Parse ( TextBox4.Text);
        Label1.ForeColor = System.Drawing.Color.FromArgb(alpha, red, green, blue);


    }   

Code generate the following output


How to change text color from ARGB value in ASP.NET

0 comments:

How to Bind Radio Button Control inside the Grid View control in ASP.NET

July 17, 2014 0 Comments

Binding process of control is same , You can bind all of controls from this method. In previous article we have  already discussed about Bind GridView in asp.net. In this example we have four radio buttons and one label control. Bind the text  of  radio button use <%# Eval(" Attribute of table") %> .
How to Bind Radio Button Control inside the Grid View control in ASP.NET

<asp:GridView ID="GridView2" runat="server" Height="202px" Width="624px" AutoGenerateColumns ="False" ShowHeader="False" AllowPaging="True">
      <Columns>
<asp:TemplateField>
    <ItemTemplate>
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Question") %>'></asp:Label><br />
     
            <asp:RadioButton ID="R1" runat="server" Text ='<%# Eval ("Answer-1") %>' GroupName ="g1" />
         <asp:RadioButton ID="R2" runat="server" Text ='<%# Eval ("Answer-2") %>' GroupName ="g1" />
         <asp:RadioButton ID="R3" runat="server" Text ='<%# Eval ("Answer-3") %>' GroupName ="g1"/>
         <asp:RadioButton ID="R4" runat="server" Text ='<%# Eval ("Answer-4") %>' GroupName ="g1"/>
    </ItemTemplate>
    <ItemStyle BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" />
</asp:TemplateField></Columns> </asp:GridView>

Codebehind code

 private void Bindabledata()
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "select * from [Question_Table]";
        cmd.Connection = con;
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        GridView2.DataSource = ds;
        GridView2.DataBind();

    }

Code generate the following output

0 comments:

Clock in windows phone 8

July 13, 2014 0 Comments

In this article,  i will use  DispatcherTimer class for creating timer control. Using interval property of this class, i will set the increment counter. After set the interval you can call tick event of this class. On tick event you can take current date and time. .
To create a new app in windows phone 8, the steps are listed below:
Create a new project by going through File | New Project | Windows Phone Application - Visual C#. Give a desired project name( World Clock is my app name).
create a new app in windows phone 8

From Solution Explorer, open MainPage.xaml file. (If Solution Explorer window is currently not opened then open it via View>>Other Windows>>Solution Explorer).
Inside Control Panel code fragment, add following code to create world clock app.

Source code (MainPage.xaml)

 <TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="436" Height="63" x:Name="label1" FontSize="30" Grid.ColumnSpan="2"/>

Code behind 

   DispatcherTimer t1 = new DispatcherTimer();
    t1.Interval = TimeSpan.FromSeconds(1);
            t1.Tick += OnTick;
            t1.Start();

  void OnTick(Object sender, EventArgs args)
        {
            label1.Text = DateTime.Now.ToString();
        }

Code Generate the following output

Clock in windows phone 8

0 comments:

How to Get text of radio button using JQuery

July 09, 2014 0 Comments

If you want to get Text from radio button then first to determine whether the radio button is checked or not , if it is checked then return true. Using the name property, you will get element of  html control. ':Checked' property check the status of html control. Suppose your radio button return true (it means checked) then you will get the value of radio button control using the val( ) method.

Now lets take an simple example

<%@ Page Language="c#" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">   
    <title>Get Text Of Radio Button</title>


    <script src="Scripts/jquery-1.10.2.js"></script>
    <script>
        $(function () {
            $('#Button1').click(function () {
                var rdtxt = $('input[name=rd]:Checked').val();
                alert(rdtxt);
            })
        }); 
</script>

</head>
<body>
    <form id="form1" runat="server">
        <input id="Radio1" type="radio"  value="Gender" name ="rd"/>Gender<br />
        <input id="Button1" type="button" value="button" />
    </form>
</body>
</html>


Code Generate the following output

How to Get text of radio button using JQuery

0 comments:

How to check RadioButton or CheckBox is checked or not using JQuery

July 07, 2014 0 Comments

Welcome to JQuery, using ID property of HTML element you can get attribute of element in JQuery. If you want to get any element in JQuery, Should create a function in <Script> </Script> block, now your code look like.

<script type="text/javaScript">
$(function( ) { } );
</Script>

Now, if you want to handle function on button_click event then you must retrieve button_id using '#' after that you will handle any event on it like click. Today we will learn , how to check status of control like checked or not, first to get id of that control. Also check it using this function

is(':checked')


Note :  Must add     <script src="Scripts/jquery-1.10.2.js"></script> in your head section of page . I have visual studio 2013 so i use 1.10.2. You can also use 1.8.2.js file 

Now your complete code is 


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Jquery radiobutton and checkbox status check</title>
    <script src="Scripts/jquery-1.10.2.js"></script>
    <script>
        $(function () {
            $('#bt').click(function () {

                var rdchk = $('#Radio1').is(':Checked');
                var ckchk = $('#Checkbox1').is(':Checked');
                alert("radio button status "+rdchk+" check box status "+ckchk);


            })


        });


    </script>
    <style type="text/css">
        #Radio1 {
            height: 32px;
            width: 174px;
            color :black;
        }
        #Checkbox1 {
            height: 69px;
            width: 83px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <input id="Radio1" type="radio" value="Gender" /></div>
        <input id="Checkbox1" type="checkbox" /><br />
    <button id="bt">Check Staus</button>
    </form>
   
        
</body>
</html>

Code generate the following code

How to check RadioButton or CheckBox is checked or not using JQuery

0 comments:

How to send bulk email in asp.net

July 04, 2014 1 Comments

If you want to send email in bulk then you should go for my algorithm. I have already learn about SMTP services (how to to send e-mail). Today we will learn , how to send email in bulk. There are various steps to send email in bulk, these are
1. Bind proper information of customer in gridview (learn how to bind gridview in asp.net)


2. Make user friendly application, in which you can insert data in gridview at runtime.(How to insert data into database)
3. Take two textboxes on design window for email-subject and email-message.
4. Also add single button control for sending message.
5. Raise click_event for button control.
6. Run foreach loop for all rows of gridview like

foreach (GridViewRow  gdata in GridView1 .Rows)
        {
}
7. Extract e-mail field from gridview, now, your code look like.

 string email = gdata.Cells[3].Text.Trim();

8. After retrieving single address from gridview, now you can send message.

9. Run your application.


Complete code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Net.Mail;

public partial class daclass : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString =ConfigurationManager.ConnectionStrings ["ConnectionString"].ToString();
        con.Open();
        SqlCommand cmd=new SqlCommand ();
        cmd.CommandText ="select * from [user]";
        cmd.Connection =con;
        SqlDataAdapter da=new SqlDataAdapter (cmd);
        DataSet ds=new DataSet();
        da.Fill (ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();          
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow  gdata in GridView1 .Rows)
        {
            string email = gdata.Cells[3].Text.Trim();
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("your gmail id here");
            msg.To.Add(email);
            msg.Subject = TextBox1.Text;
            msg.Body = TextBox2.Text;
            msg.IsBodyHtml = true;
            SmtpClient smt = new SmtpClient("smtp.gmail.com", 587);
            smt.EnableSsl = true;
            smt.Credentials = new System.Net.NetworkCredential("your gmail id here", "your gmail password");
            smt.Send(msg);
            Response.Write("message send");
            
        }
    }
}

Code Generate the following output
How to send bulk email in asp.net

How to send bulk email in asp.net

1 comments:

If statement in c#

July 01, 2014 0 Comments

Its also known as conditional statement, in c# there are two types of conditional statements. First one is if statement and second one is switch statement. In this article we will learn about if statement, basically if statement depends on condition. If your statement condition is true then if statement is executed otherwise not. Lets take an simple example
Suppose you have a variable  a of type int with having some value (take from user input). Like

int a= int.Parse(Console.ReadLine());
Now, if you want to compare this value from other value like 10. Now your statement look like
if(a==10)
{
   Console.writeLine("Your Number is 10");

}
So lets analyze this code, Now start from if statement , if statement needs a Boolean expression. In this code , evaluate the expression, which is inside in if bracket. Also return true as well as false Boolean value. If code return true then execute if block. Similarly we create multiple if block like

if(a==10)
{
   Console.writeLine("Your Number is 10");

}
if(a==20)
{
   Console.writeLine("Your Number is 20");

}
if(a==30)
{
   Console.writeLine("Your Number is 30");

}

If user enter any number, if entered number match with among given numbers then compiler display a  related message.

Disadvantage of multiple if statement is 

if first condition is match with entered value, processed should be closed but in case of multiple if statement, all condition would be checked. You can say its take more time.

So overcome this problem, you must use else-if statement. In case of else-if some false statement will be skipped. Like

if(a==10)
{
   Console.writeLine("Your Number is 10");

}
else if(a==20)
{
   Console.writeLine("Your Number is 20");

}

If your first condition is true then compiler will not check else-if condition, if first condition returns false then compiler will go to the else statement.

0 comments: